How do i send keys using a global keyboard hook?

喜欢而已 提交于 2019-12-06 05:28:54

问题


I'm trying to send keys to an application which does not respond to any of the API's that I have so far used (SendInput(), PostMessage(), SendMessage() and others). However, i tested Windows' On-Screen Keyboard Utility and pressed the keys i needed and the application received these keys easily.

If i understand correctly the keyboard utility uses global keyboard hooks to send the keys, so I'm interested i how i could do so as well. I have tried finding examples of how this can be done on google but have come up with no results.

Thanks.


回答1:


Hooks are used to intercept the events, not to send new event. So what you're asking is impossible with hooks. SendInput is the way to go. probably you did something wrong, so it'll be better if you post your code that doesn't work and debug what went wrong.




回答2:


I solved it. I was sending keys to a DirectX application. Turns out i had to send DirectX scan codes instead of regular VK_KEY's.

A list of scan codes can be found at: http://www.gamespp.com/directx/directInputKeyboardScanCodes.html

Using these with SendInput() and everything worked great.

Thanks for the help also.

Cheers.



来源:https://stackoverflow.com/questions/6971277/how-do-i-send-keys-using-a-global-keyboard-hook

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!