mouse_event(MOUSEEVENTF_ABSOLUTE|MOUSEEVENTF_LEFTDOWN,0,0,0,0);
mouse_event(MOUSEEVENTF_ABSOLUTE|MOUSEEVENTF_LEFTUP,0,0,0,0);
这是一个DX游戏``我想在当前位置里单击``可是不行啊```晕``请教还有没有别的办法啊??

解决方案 »

  1.   

    你想模拟鼠标、键盘等的事件吗?可以试试SendInput:
    The SendInput function synthesizes keystrokes, mouse motions, and button clicks.UINT SendInput(
      UINT nInputs,     // count of input events
      LPINPUT pInputs,  // array of input events
      int cbSize        // size of structure
    );例如:  
    (此例表示将鼠标移动到pos,然后右键单击)         int count=0;
             INPUT input[3]; input[count].type=INPUT_MOUSE;
    input[count].mi.dx=pos.x;
    input[count].mi.dy=pos.y;
    input[count].mi.dwFlags=MOUSEEVENTF_ABSOLUTE|MOUSEEVENTF_MOVE;
    input[count].mi.dwExtraInfo=NULL;
    input[count].mi.mouseData=NULL;
    input[count].mi.time=NULL;
    count++; input[count].type=INPUT_MOUSE;
    input[count].mi.dx=pos.x;
    input[count].mi.dy=pos.y;
    input[count].mi.dwFlags=MOUSEEVENTF_ABSOLUTE|MOUSEEVENTF_RIGHTDOWN;
    input[count].mi.dwExtraInfo=NULL;
    input[count].mi.mouseData=NULL;
    input[count].mi.time=NULL;
    count++; input[count].type=INPUT_MOUSE;
    input[count].mi.dx=pos.x;
    input[count].mi.dy=pos.y;
    input[count].mi.dwFlags=MOUSEEVENTF_ABSOLUTE|MOUSEEVENTF_RIGHTUP;
    input[count].mi.dwExtraInfo=NULL;
    input[count].mi.mouseData=NULL;
    input[count].mi.time=NULL;
    count++; int ret=SendInput(count,input,sizeof(INPUT));
      

  2.   

    // 
      // 在鼠标当前位置  鼠标左键单击
      //
      ::mouse_event(MOUSEEVENTF_LEFTDOWN,0,0,0,0);// 鼠标左键按下
      ::mouse_event(MOUSEEVENTF_LEFTUP,0,0,0,0);  // 鼠标左键抬起 
      你的参数不对吧, MOUSEEVENTF_ABSOLUTE 使用来和 位置 配合使用的
      

  3.   

    1、首先我们要知道现在鼠标的位置(为了好还原现在鼠标的位置)所以我们就要用到API函数GetCursorPos,它的使用方法如下:
    BOOL GetCursorPos(    LPPOINT lpPoint  // address of structure for cursor position  
       );
    2、我们把鼠标的位置移到要到人物走到的地方,我们就要用到SetCursorPos函数来移动鼠标位置,它的使用方法如下:
    BOOL SetCursorPos(    int X, // horizontal position  
        int Y  // vertical position
       );
    3、模拟鼠标发出按下和放开的动作,我们要用到mouse_event函数来实现,具休使用方法用下:
    VOID mouse_event(    DWORD dwFlags, // flags specifying various motion/click variants
        DWORD dx, // horizontal mouse position or position change
        DWORD dy, // vertical mouse position or position change
        DWORD dwData, // amount of wheel movement
        DWORD dwExtraInfo  // 32 bits of application-defined information
       );
    在它的dwFlags处,可用的事件很多如移动MOUSEEVENTF_MOVE,左键按下MOUSEEVENTF_LEFTDOWN,左键放开MOUSEEVENTF_LEFTUP,具体的东东还是查一下MSDN吧~~~~~
    好了,有了以前的知识,我们就可以来看看人物移走是怎么实现的了:  getcursorpos(point);
      setcursorpos(ranpoint(80,windowX),ranpoint(80,windowY));//ranpoint是个自制的随机坐标函数
      mouse_event(MOUSEEVENTF_LEFTDOWN,0,0,0,0);
      mouse_event(MOUSEEVENTF_LEFTUP,0,0,0,0);
      setcursorpos(point.x,point.y);看了以上的代码,是不是觉得人物的游走很简单啦~~,举一仿三,还有好多好东东可以用这个技巧实现(我早就说过,TMD,这是垃圾外挂的做法,相信了吧~~~),接下来,再看看游戏里面自动攻击的做法吧(必需游戏中攻击支持快捷键的),道理还是一样的,只是用的API不同罢了~~~,这回我们要用到的是keybd_event函数,其用法如下:
    VOID keybd_event(    BYTE bVk, // virtual-key code
        BYTE bScan, // hardware scan code
        DWORD dwFlags, // flags specifying various function options
        DWORD dwExtraInfo  // additional data associated with keystroke
       );
    我们还要知道扫描码不可以直接使用,要用函数MapVirtualKey把键值转成扫描码,MapVirtualKey的具体使用方法如下:
    UINT MapVirtualKey(    UINT uCode, // virtual-key code or scan code
        UINT uMapType  // translation to perform
       );
    好了,比说此快接键是CTRL+A,接下来让我们看看实际代码是怎么写的:  keybd_event(VK_CONTROL,mapvirtualkey(VK_CONTROL,0),0,0);
      keybd_event(65,mapvirtualkey(65,0),0,0);
      keybd_event(65,mapvirtualkey(65,0),keyeventf_keyup,0);
      keybd_event(VK_CONTROL,mapvirtualkey(VK_CONTROL,0),keyeventf_keyup,0);首先模拟按下了CTRL键,再模拟按下A键,再模拟放开A键,最后放开CTRL键,这就是一个模拟按快捷键的周期。
      

  4.   

    那些什么MOUSEEVENTF_LEFTDOWN的标记``所有的组合我都试过了```楼上说的都是一些基本知识``我都知道、用过``。。
      

  5.   

    GetCursorPos Function--------------------------------------------------------------------------------The GetCursorPos function retrieves the cursor's position, in screen coordinates. SyntaxBOOL GetCursorPos(          LPPOINT lpPoint
    );
    ParameterslpPoint
    [out] Pointer to a POINT structure that receives the screen coordinates of the cursor. 
    Return ValueIf the function succeeds, the return value is nonzero.If the function fails, the return value is zero. To get extended error information, call GetLastError.
    ResThe cursor position is always specified in screen coordinates and is not affected by the mapping mode of the window that contains the cursor. The calling process must have WINSTA_READATTRIBUTES access to the window station. ExampleFor an example, see Using the Keyboard to Move the Cursor.Function InformationMinimum DLL Version user32.dll 
    Header Declared in Winuser.h, include Windows.h 
    Import library User32.lib 
    Minimum operating systems Windows 95, Windows NT 3.1 
      

  6.   

    MOUSEMOVEPOINT Structure--------------------------------------------------------------------------------The MOUSEMOVEPOINT structure contains information about the mouse's location in screen coordinates.Syntaxtypedef struct tagMOUSEMOVEPOINT {
        int x;
        int y;
        DWORD time;
        ULONG_PTR dwExtraInfo;
    } MOUSEMOVEPOINT, *PMOUSEMOVEPOINT;
    Membersx
    Specifies the x-coordinate of the mouse. 
    y
    Specifies the y-coordinate of the mouse. 
    time
    Specifies the time stamp of the mouse coordinate. 
    dwExtraInfo
    Specifies extra information associated with this coordinate. 
    Structure InformationHeader Declared in Winuser.h, include Windows.h 
    Minimum operating systems Millennium, Windows 2000 
      

  7.   

    是可以的,我在DX的游戏中使用过。你的函数调用错了
    应该是:
      mouse_event(MOUSEEVENTF_LEFTDOWN,0,0,0,0);
      //稍微加一点延时间。因为真的鼠标大约8ms采样一次。有的游戏在计算单击的时候,可能需要时间 戳
      Sleep(8);
      mouse_event(MOUSEEVENTF_LEFTUP,0,0,0,0);
      

  8.   

    用应用程序模拟键盘和鼠标按键作者:Owen.Guo VC知识库 在Windows大行其道的今天,windows界面程序受到广大用户的欢迎。对这些程序的操作不外乎两种,键盘输入控制和鼠标输入控制。有时,对于繁杂的,或重复性的输入操作,我们能否通过编制程序来代替手工输入,而用程序来模拟键盘及鼠标的输入呢?答案是肯定的。这里主要是通过两个Windows API函数来实现的。下面以 VC++为例来介绍一下如何实现这两个功能。
    下载本文示例代码
    模拟键盘我们用Keybd_event这个api函数,模拟鼠标按键用mouse_event函数。在VC里调用api函数是既简单又方便不过的事了。  首先介绍一下Keybd_event函数。Keybd_event能触发一个按键事件,也就是说回产生一个WM_KEYDOWN或WM_KEYUP消息。当然也可以用产生这两个消息来模拟按键,但是没有直接用这个函数方便。Keybd_event共有四个参数,第一个为按键的虚拟键值,如回车键为 vk_return, tab键为vk_tab。第二个参数为扫描码,一般不用设置,用0代替就行第三个参数为选项标志,如果为keydown则置0即可,如果为keyup则设成“KEYEVENTF_KEYUP”,第四个参数一般也是置0即可。用如下代码即可实现模拟按下键,其中的XX表示XX键的虚拟键值,在这里也就是各键对应的键码,如’A’=65keybd_event(65,0,0,0);keybd_event(65,0,KEYEVENTF_KEYUP,0); ...  mouse_event最好配合SetCursorPos(x,y)函数一起使用,与Keybd_event类似,mouse_event有五个参数,第一个为选项标志,为MOUSEEVENTF_LEFTDOWN时表示左键按下为MOUSEEVENTF_LEFTUP表示左键松开,向系统发送相应消息。第二三个参数分别表示x,y相对位置,一般可设为0,0,第四五个参数并不重要,一般也可设为0,0。若要得到Keybd_event和mouse_event函数的更详细的用法,可以查阅msdn或delphi帮助。
    下面是关于mouse_event的示例代码:
    POINT lpPoint;GetCursorPos(&lpPoint);SetCursorPos(lpPoint.x, lpPoint.y);mouse_event(MOUSEEVENTF_LEFTDOWN,0,0,0,0);mouse_event(MOUSEEVENTF_LEFTUP,0,0,0,0);
      上面的代码表示鼠标的双击,若要表示单击,用两个mouse_event即可(一次放下,一次松开)。    注意,不管是模拟键盘还是鼠标事件,都要注意还原,即按完键要松开,一个keydown对应一个keyup;鼠标单击完也要松开, 不然可能影响程序的功能。