哪位高手开发过模拟器WinKawaks1.45飞雪外挂,如何模拟键盘控制人物的动作和行走?万分感谢!
  如能对我有用,愿再给100分!

解决方案 »

  1.   

    模拟键盘消息就可以了,比如说找一个 Ben's MsgSimulator 控件就可以
      

  2.   

    用以下两个API在受控机器上模拟键盘和鼠标输入:
    keybd_event
    mouse_event
      

  3.   

    sendkeys('{ENTER}',false);
       SetCursorPos(strtoint(x1.Text),strtoint(y1.Text));
       Mouse_Event(MOUSEEVENTF_LEFTDOWN,strtoint(x1.Text),strtoint(y1.Text),0,0);
       Mouse_Event(MOUSEEVENTF_LEFTUP,strtoint(x1.Text),strtoint(y1.Text),0,0);
       Mouse_Event(MOUSEEVENTF_RIGHTDOWN,strtoint(x1.Text),strtoint(y1.Text),0,0);
       Mouse_Event(MOUSEEVENTF_RIGHTUP,strtoint(x1.Text),strtoint(y1.Text),0,0);
       SetCursorPos(strtoint(x2.Text),strtoint(y2.Text));
       Mouse_Event(MOUSEEVENTF_LEFTDOWN,strtoint(x2.Text),strtoint(y2.Text),0,0);
       Mouse_Event(MOUSEEVENTF_LEFTUP,strtoint(x2.Text),strtoint(y2.Text),0,0);
    简单的列子
      

  4.   

    忘了说明了,x1,y1,x2,y2都是坐标
      

  5.   

    我试过了,keybd_event与mouse_event有的些程序中可以,有些程序中不可以,比台说在   模拟器WinKawaks1.45飞雪  就不可以,请是怎么回事?是因为   模拟器WinKawaks1.45飞雪  做了什么用脚吗?还是它跟本就不处理我用keybd_event与mouse_event产生的消呢?我用的PostMessage和SendMesage好象不行!????
      

  6.   

    我写的 DLL 代码如下,请大家看看,那里有问题呀:
    Library KEYHOOK ;uses
      Windows,
      UnitHOOK in 'UnitHOOK.pas';exports // 定义输出函数
      InstallKeyBoardHook ,
      UnInstallKeyBoardHook ;begin // DLL 初始化部分end.另一个单元文件:
    unit UnitHOOK ;interfaceuses
      Windows , Messages;const
      HOOK_MEM_FILENAME='SAMPLE KEY_HOOK_MEM_FILE' ;
      My_user32 = 'USER32.DLL'  ;type
      TShared=record
        ThreadID : Cardinal ;
      end ;
      PShared=^TShared ;  //模拟键盘--只能模拟键盘
      TMy_keybd_event=procedure(bVk: Byte; bScan: Byte; dwFlags, dwExtraInfo: DWORD); stdcall;//external My_user32 name 'keybd_event' ;
      //模拟鼠标--只能模拟鼠标
      TMy_mouse_event=procedure(dwFlags, dx, dy, dwData, dwExtraInfo: DWORD); stdcall;// external; user32 name 'mouse_event';
      //模拟键盘与鼠标--键盘鼠标都能模拟
      TMy_SendInput=function(cInputs: UINT; var pInputs: TInput; cbSize: Integer): UINT; stdcall;// external My_user32 name 'SendInput';var
      MemFile : THandle ;
      HHook : Thandle ;
      Shared : PShared ;  function HookProcKeyBoard(Code: Integer; wParam: WPARAM ; lParam: LPARAM):LRESULT;stdcall;
      Procedure InstallKeyBoardHook ; Stdcall ; export ;
      Procedure UnInstallKeyBoardHook ; Stdcall ; export ;implementationtype
      TCustom_Input = Array[0..2] of TInput ;
    var
      H_Module : THandle ;
      My_keybd_event : TMy_keybd_event ;
      My_mouse_event : TMy_mouse_event ;
      My_SendInput : TMy_SendInput ;Procedure Custom_SendInput(VK : Cardinal) ; //模拟按键
    var
      Input : TCustom_Input ;
    begin
      Input[0].Itype := INPUT_KEYBOARD ;
      Input[0].ki.wVk := VK ;
      Input[0].ki.wScan := MapVirtualKey(VK,0) ;
      Input[0].ki.dwFlags := 0 ;
      Input[0].ki.time := GetTickCount ;
      Input[0].ki.dwExtraInfo := 0 ;  Input[1].Itype := INPUT_KEYBOARD ;
      Input[1].ki.wVk := VK ;
      Input[1].ki.wScan := MapVirtualKey(VK,0) ;
      Input[1].ki.dwFlags := KEYEVENTF_KEYUP ;
      Input[1].ki.time := GetTickCount ;
      Input[1].ki.dwExtraInfo := 0 ;  My_SendInput(1,Input[0],Sizeof(TInput)) ;
      My_SendInput(1,Input[1],Sizeof(TInput))
    end ;Procedure Custom_keybd_event(VK : Cardinal) ; //模拟按键
    begin
      My_keybd_event(VK,MapVirtualKey(VK,0),0,0) ;                 //模拟按键
      My_keybd_event(VK,MapVirtualKey(VK,0),KEYEVENTF_KEYUP,0) ;   //模拟放键
      KEYEVENTF_EXTENDEDKEY
    end ;Procedure Custom_SendMessage(VK : Cardinal) ; //模拟按键
    var
      HForegroundWindow : Thandle ;
      HSub_ForegroundWindow : Thandle ;
    begin
      HForegroundWindow := Windows.GetForegroundWindow ;
      HSub_ForegroundWindow := Windows.FindWindowEx(HForegroundWindow,0,'Afx:400000:b:10011:6:0',nil) ;
      Windows.SendMessage(HSub_ForegroundWindow,Messages.WM_KEYDOWN,VK,$00000001) ;
      Windows.SendMessage(HSub_ForegroundWindow,Messages.WM_KEYUP,VK,$00000001) ;
    end ;// 键盘回调函数处理...
    function HookProcKeyBoard(Code: Integer; wParam: WPARAM ; lParam: LPARAM):LRESULT;
    const
      KeyPressMask = $80000000 ;
    var
      VK : Cardinal ;
    begin
      Result := 0 ;
      if Code < 0 then
        Result := CallNextHookEx(HHook,Code,wParam,lParam)
      else if Code = HC_ACTION then
      begin
        if (lParam and KeyPressMask) = 0 then
        begin
          if wParam = VK_F12 then  //启动键
          begin
            VK := Ord('A') ;
            Custom_keybd_event(VK) ;
          end ;
        end ;
        Result := CallNextHookEx(HHook,Code,wParam,lParam) ;
      end
      else if Code = HC_NOREMOVE then
      begin
        Result := CallNextHookEx(HHook,Code,wParam,lParam) ;
      end ;
    end;// 设置键盘钩子过滤函数
    Procedure InstallKeyBoardHook ;
    begin
      HHook:=SetWindowsHookEx(WH_KEYBOARD,@HookProcKeyBoard,HInstance,0) ;
      if hHook = 0 then
        Exit ;
    end ;//撤消键盘钩子过滤函数
    Procedure UnInstallKeyBoardHook ;  
    begin
      UnHookWindowsHookEx(HHook) ;
      hHook:=0;
    end ;Initialization
    begin
      MemFile:=OpenFileMapping(FILE_MAP_WRITE,False,HOOK_MEM_FILENAME);  // 通过建立内存映象文件以共享内存
      if MemFile=0 then
        MemFile:=CreateFileMapping($FFFFFFFF,nil,PAGE_READWRITE,0,SizeOf(TShared),HOOK_MEM_FILENAME) ;
      Shared := MapViewOfFile(MemFile,File_MAP_WRITE,0,0,SizeOf(TShared)) ;  H_Module := Windows.LoadLibrary(My_user32) ;
      @My_keybd_event := Windows.GetProcAddress(H_Module,'keybd_event') ;
      @My_mouse_event := Windows.GetProcAddress(H_Module,'mouse_event') ;
      @My_SendInput := Windows.GetProcAddress(H_Module,'SendInput') ;
    end ;Finalization
    begin
      if hHook <> 0 then
        UnInstallKeyBoardHook ;
      UnMapViewOfFile(Shared) ;  // 释放内存映象文件
      CloseHandle(MemFile) ;     // 关闭映象文件
      Windows.FreeLibrary(H_Module) ;
    end ;end.
    我的代码如上,请大家帮我看看那里有问题?是什么原因?模拟键盘不成功?
      

  7.   

    控制键盘鼠标有很多种方法的,不一定要通过Win32的消息机制。如果人家用DirectInput或者直接用中断请求方式,Hook Win32 Msg API 根本不起作用
      

  8.   

    to _EP_EvilKiss(_EP_EvilKiss) 
     你好,可以说详细点吗?我不太明白!