关于按键HOOK的一些问题,WINDOWAPI(50分)

  • 主题发起人 主题发起人 々^丫y
  • 开始时间 开始时间

々^丫y

Unregistered / Unconfirmed
GUEST, unregistred user!
我主要想是在任意窗口模拟键盘操作<br>用keybd_event,有的窗口可以模拟,有的又不行<br>然后我用<br>SetForegroundWindow(GetForegroundWindow);<br>SendMessage(GetForegroundWindow,WM_keydown,89,0);<br>通过GetForegroundWindow得到句柄,设置为当前窗体,发按键消息,但没有反应.<br>PostMessage也试过了,为什么?<br>我句柄那里错了?还是其他什么地方有问题?
 
[:(!][:(!]我顶哟,没人回答
 
你是往游戏里面发送按键?那没那么容易哦,人家键盘鼠标都重新做了驱动
 
如果不是往游戏里发,是往一般的窗口?<br>如我往记事本里发应该怎么发?
 
我往记事本里发,我上面那代码也不行呀
 
http://www.delphisearch.cn/?key=SendMessage+%BC%C7%CA%C2%B1%BE+%B0%B4%BC%FC<br><br>学会搜索哦
 
function KeyboardHookHandler(iCode: Integer;<br>wParam: WPARAM;<br>lParam: LPARAM ): LRESULT; stdcall; export;<br>const<br>_KeyPressMask = $80000000;<br>var<br>i:integer;<br>Key_S:String;<br>H:Thandle;<br>begin<br>&nbsp; Result := 0;<br>&nbsp; if R_point&gt;0 then<br>&nbsp; begin<br>&nbsp; iCode:=-1;<br>&nbsp; R_point:=R_point-1;<br>&nbsp; end;<br>&nbsp; If iCode &lt; 0 Then<br>&nbsp; begin<br>&nbsp; &nbsp; Result := CallNextHookEx(DnfNextHook, iCode, wParam, lParam);<br>&nbsp; &nbsp; Exit;<br>&nbsp; end;<br><br>&nbsp; &nbsp; &nbsp; for i:=0 to Key_.Count-1 do<br>&nbsp; &nbsp; &nbsp; begin <br>&nbsp; &nbsp; &nbsp; Key_S:=Key_;<br>&nbsp; &nbsp; &nbsp; if ((lParam and _KeyPressMask) = 0) and &nbsp; <br>&nbsp; &nbsp; &nbsp; (wParam = Ord(Key_S[1])) then <br>&nbsp; &nbsp; &nbsp; &nbsp;begin<br>&nbsp; &nbsp; &nbsp; &nbsp; Result := 1; &nbsp; &nbsp;<br>&nbsp; ///在这里处理我的活动窗口发送按钮,不成功SendMessage,PostMessage都不行<br>&nbsp; ///直接用keybd_event可以.<br>&nbsp; //如果打开记事本,当前窗口打开后,我按A按钮,响应的应该是在记事本里写上B<br>&nbsp; &nbsp; &nbsp; &nbsp; SetForegroundWindow(GetForegroundWindow);<br>&nbsp; &nbsp; &nbsp; &nbsp; SendMessage(GetActiveWindow,WM_KEYDOWN,66,0);<br>&nbsp; &nbsp; &nbsp; &nbsp; SendMessage(GetActiveWindow,WM_KEYUP,66,0);<br><br>&nbsp; &nbsp; &nbsp; &nbsp;end;<br>&nbsp; &nbsp; &nbsp; end;<br>end;
 
顶上,拜托回答
 
再顶呀,拜托,请回答
 
AttachThreadInput
 
----wql<br>你意思是用AttachThreadInput把他的线程共享后<br>再进行发送消息,发到窗口?还是线成?<br>sendMessage?还是postMessage<br>,你能在具体点吗,WQL
 
我顶呀顶呀顶呀顶
 
你是想对游戏进行的模拟的??<br>游戏里面是把你这消息给截了.<br>而游戏里面的是用directinput来直接底层对硬件操作,而不是用消息的方式....<br>你可以用directinput来试试...或者模拟硬件吧....你找一下winio这东东...
 
多人接受答案了。
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
I
回复
0
查看
687
import
I
后退
顶部