碧海潮声大学生网

标题: 〖原创〗硬件模拟鼠标点击 [打印本页]

作者: qiuq86    时间: 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;
        }
      }
   }
}
作者: qiuq86    时间: 2006-11-5 17:55
使用方法是按下A键,记录当前鼠标所在位置作为第一个点击点,再按下B键,记录当前鼠标位置作为第二个点。然后两个点能轮换点击,时间间隔我这里设为11秒了,各位可以自己修改。
作者: gemirain    时间: 2006-11-5 18:15
呵呵
作者: 我是誰    时间: 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,具体我就不贴了。
作者: 我是誰    时间: 2006-11-6 10:20
蒸汽幻想? 没听说过。不过游戏我听说的也就那几种,呵呵。
作者: qiuq86    时间: 2006-11-6 12:42
SendInput我倒是没试过,我先试试你说的那两个函数吧。不过我估计还是会不行的,网游设计者会比我们更清楚这些函数吧,或者说如何防止我们用外挂。谢谢你的意见。
作者: qiuq86    时间: 2006-11-6 12:47
另外,你的梦幻西游外挂做好了可以让我看看吗,呵呵
作者: 我是誰    时间: 2006-11-6 14:36
一般,反外挂只是针对Hook及修改内存和封包的。针对键盘鼠标模拟类的,并没有什么“屏蔽API”的说法。只不过游戏响应的消息不同而已。要验证游戏能不能用外挂,使用“按键精灵”试试就知道了。只要按键精灵有用,你自己同样也能实现。自己多调试一下就行。

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

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


高手 就是高手啊
作者: qiuq86    时间: 2006-11-6 18:04
呵呵,这样啊。恩,那看外挂就不勉强了,不过我也是对外挂比较感兴趣,以后就来请教你哦。我用按键精灵试过的,不行的,一运行还原精灵就会被检测出来。我去还原精灵的论坛看过,据说用只能用硬件模拟模式,而且只能对单点进行循环定时点击。所以才想办法从硬件层次上模拟鼠标点击。
作者: 我是誰    时间: 2006-11-6 18:47
检测出按键精灵只能说明这个游戏是专门防按键精灵而已。通过FindWindow等函数实现。毕竟按键精灵的名头太大了。The SendInput function inserts the events in the INPUT structures serially into the keyboard or mouse input stream.一般所说的硬件模拟也就是这个了,直接发送按键到输入流中。Mouse_event只是在XP下不被推荐,但也是可以使用的。你可以多试着调试一下,比如加大sleep的间隔。最好用spy++分析一下窗口的消息流。
如果你要再“硬”的话,那只有写鼠标驱动了。

另外,使用C来做外挂,貌似难度大了点,难道就这么个黑黑的样子?还有,代码有点没看懂。你暂停11秒,为啥不直接sleep(11000);而是用循环?或许我太菜了吧,嗬嗬
作者: qiuq86    时间: 2006-11-7 13:26
恩,最近可能运动会会有好多时间,慢慢试吧,呵呵。
我只是拿来玩玩呀,还没想要商业化,自己用的话,好用就可以了。
那个十一秒是因为我在用的是C-Free,好多c标准库函数都不支持的,呵呵,见笑了 [s:64]
作者: 海院の水水    时间: 2006-11-7 13:53
一群高手 ` `  闪人 `
作者: 我是誰    时间: 2006-11-7 17:24
引用第11楼qiuq862006-11-07 13:26发表的“”:
那个十一秒是因为我在用的是C-Free,好多c标准库函数都不支持的,呵呵,见笑了 [s:64]
这个跟标准函数没什么关系。sleep同样是Windows API函数。而且我是问你为什么要循环调用十一次sleep(1000),而不直接sleep(11000)呢?
作者: 笨鸟想先飞    时间: 2007-1-3 16:55
那个~我是谁~你真的厉害啊,我们能不能认识一下啊???
作者: lk3518127    时间: 2007-1-20 17:38
大哥门 说具体点 怎么 自动采矿教教啊

谢谢啊各个门




欢迎光临 碧海潮声大学生网 (http://www.zjoubbs.com/) Powered by Discuz! X3.2