找回密码

碧海潮声大学生网

查看: 3342|回复: 15
打印 上一主题 下一主题

〖原创〗硬件模拟鼠标点击

[复制链接]
跳转到指定楼层
1#
发表于 2006-11-5 17:44 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
写了一个调用WINDOWS API函数模拟鼠标点击的C语言程序,本来是用来做‘蒸汽幻想’的采矿外挂的,但是好像游戏程序屏蔽了这些API,不知有没有哪位有直接写硬件端口模拟鼠标点击的方法。

以下是代码:
#include<stdio.h>
#include<windows.h>
#include<dos.h>

typedef struct poi
{
   long x;
   long y;
}point;

int sd=0,choose=0;
point pt1,pt2,ptn;

main()
{
   int i=0,j=0,x,y;
   char key;
   printf("Welcome to AutoClick program!!\n----QiuQ\n");
   /*读取第一个点击点*/
   key=getche();
   if(key==&#39;a&#39;||key==&#39;A&#39;)
      GetCursorPos(&pt1);
   printf("pt1.x = %ld , pt1.y = %ld\n",pt1.x,pt1.y);
   /*读取第二个点击点*/
   key=getche();
   if(key==&#39;b&#39;||key==&#39;B&#39;)
      GetCursorPos(&pt2);
   printf("pt2.x = %ld , pt2.y = %ld\n",pt2.x,pt2.y);
   /*进入循环体*/
   while(sd!=1)
   {
      GetCursorPos(&ptn);
      if(ptn.x==0||ptn.y==0)
        break;
      else
      {
        if(choose==0)
        {
           SetCursorPos(pt1.x,pt1.y);
           printf("clicking point one...%d\n",i);
           mouse_event(MOUSEEVENTF_LEFTDOWN,pt1.x,pt1.y,0,0);
           sleep(200);
           mouse_event(MOUSEEVENTF_LEFTUP,pt1.x,pt1.y,0,0);
           mouse_event(MOUSEEVENTF_LEFTDOWN,pt1.x,pt1.y,0,0);
           sleep(200);
           mouse_event(MOUSEEVENTF_LEFTUP,pt1.x,pt1.y,0,0);
           for(x=0;x<11;x++)
           {
              sleep(1000);printf("%d ",x);
           }
           printf("\n");
           i++;
           choose=1;
        }
        else if(choose==1)
        {
           SetCursorPos(pt2.x,pt2.y);
           printf("clicking point two...%d\n",j);
           mouse_event(MOUSEEVENTF_LEFTDOWN,pt2.x,pt2.y,0,0);
           sleep(200);
           mouse_event(MOUSEEVENTF_LEFTUP,pt2.x,pt2.y,0,0);
           mouse_event(MOUSEEVENTF_LEFTDOWN,pt2.x,pt2.y,0,0);
           sleep(200);
           mouse_event(MOUSEEVENTF_LEFTUP,pt2.x,pt2.y,0,0);
           for(x=0;x<11;x++)
           {
              sleep(1000);printf("%d ",x);
           }
           printf("\n");
           j++;
           choose=0;
        }
      }
   }
}

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享分享 顶 踩
2#
 楼主| 发表于 2006-11-5 17:55 | 只看该作者
使用方法是按下A键,记录当前鼠标所在位置作为第一个点击点,再按下B键,记录当前鼠标位置作为第二个点。然后两个点能轮换点击,时间间隔我这里设为11秒了,各位可以自己修改。
3#
发表于 2006-11-5 18:15 | 只看该作者
呵呵
4#
发表于 2006-11-6 10:15 | 只看该作者
模拟鼠标点击,NT/2000/XP下,推荐使用SendInput函数。keybd_event及mouse_event已不被推荐使用。另外,你试试使用PostMessage函数来直接发送鼠标消息。我最近在做的"梦幻西游"外挂,都是使用PostMessage.可以先使用Spy++来查看一下游戏窗口接收的消息。

SendInput用法:
SendInput Function

--------------------------------------------------------------------------------

The SendInput function synthesizes keystrokes, mouse motions, and button clicks.

Syntax

UINT SendInput(       UINT nInputs,
   LPINPUT pInputs,
   int cbSize
);
Parameters

nInputs
[in] Specifies the number of structures in the pInputs array.
pInputs
[in] Pointer to an array of INPUT structures. Each structure represents an event to be inserted into the keyboard or mouse input stream.
cbSize
[in] Specifies the size, in bytes, of an INPUT structure. If cbSize is not the size of an INPUT structure, the function will fail.
Return Value

The function returns the number of events that it successfully inserted into the keyboard or mouse input stream. If the function returns zero, the input was already blocked by another thread.

To get extended error information, call GetLastError.




Remarks

The SendInput function inserts the events in the INPUT structures serially into the keyboard or mouse input stream. These events aren&#39;t interspersed with other keyboard or mouse input events inserted either by the user (with the keyboard or mouse) or by calls to keybd_event, mouse_event, or other calls to SendInput.

This function does not reset the keyboard&#39;s current state. Any keys that are already pressed when the function is called might interfere with the events that this function generates. To avoid this problem, check the keyboard&#39;s state with the GetAsyncKeyState function and correct as necessary.

PostMessage用法自己看MSDN吧,要发送的消息为WM_MOUSEMOVE,WM_LBUTTONDOWN ,WM_LBUTTONUP,具体我就不贴了。
5#
发表于 2006-11-6 10:20 | 只看该作者
蒸汽幻想? 没听说过。不过游戏我听说的也就那几种,呵呵。
6#
 楼主| 发表于 2006-11-6 12:42 | 只看该作者
SendInput我倒是没试过,我先试试你说的那两个函数吧。不过我估计还是会不行的,网游设计者会比我们更清楚这些函数吧,或者说如何防止我们用外挂。谢谢你的意见。
7#
 楼主| 发表于 2006-11-6 12:47 | 只看该作者
另外,你的梦幻西游外挂做好了可以让我看看吗,呵呵
8#
发表于 2006-11-6 14:36 | 只看该作者
一般,反外挂只是针对Hook及修改内存和封包的。针对键盘鼠标模拟类的,并没有什么“屏蔽API”的说法。只不过游戏响应的消息不同而已。要验证游戏能不能用外挂,使用“按键精灵”试试就知道了。只要按键精灵有用,你自己同样也能实现。自己多调试一下就行。

我现在在做的外挂,是梦幻西游里自动任务外挂,从NPC接任务,再分析任务,到目的地抓怪。基本上也就是分析像素及键鼠模拟。技术上也较简单。不过因为是别人订做的,涉及到商业机密,就恕我不能给你看了。
9#
发表于 2006-11-6 15:55 | 只看该作者
引用第7楼我是誰2006-11-06 14:36发表的“”:
一般,反外挂只是针对Hook及修改内存和封包的。针对键盘鼠标模拟类的,并没有什么“屏蔽API”的说法。只不过游戏响应的消息不同而已。要验证游戏能不能用外挂,使用“按键精灵”试试就知道了。只要按键精灵有用,你自己同样也能实现。自己多调试一下就行。

我现在在做的外挂,是梦幻西游里自动任务外挂,从NPC接任务,再分析任务,到目的地抓怪。基本上也就是分析像素及键鼠模拟。技术上也较简单。不过因为是别人订做的,涉及到商业机密,就恕我不能给你看了。


高手 就是高手啊
10#
 楼主| 发表于 2006-11-6 18:04 | 只看该作者
呵呵,这样啊。恩,那看外挂就不勉强了,不过我也是对外挂比较感兴趣,以后就来请教你哦。我用按键精灵试过的,不行的,一运行还原精灵就会被检测出来。我去还原精灵的论坛看过,据说用只能用硬件模拟模式,而且只能对单点进行循环定时点击。所以才想办法从硬件层次上模拟鼠标点击。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|小黑屋| 碧海潮声大学生网  

Copyright © 2001-2013 Comsenz Inc.   All Rights Reserved.

Powered by Discuz! X3.2( 浙ICP备11026473号 )

快速回复 返回顶部 返回列表