Can I change a user's keyboard input?

纵然是瞬间 提交于 2019-11-30 19:10:34

I've done this before but a little different.
Instead of trying to change the parameters sent to CallNextHookEx, I 'swallowed' the key press (you can do this by returning a nonzero value from the hook procedure to prevent subsequent procedures from being called).

Then I used SendInput to send the new key that I wanted to 'inject'.

So basically it works like this:

  • Hook procedure identifies a target key is pressed
  • Call to SendInput, with the new key
  • Return 1 from the hook procedure to ignore the original key

Be careful of cyclic redirects, i.e. 'a' redirected to 'b' redirected to 'a', it can easily blow up ;)

You have, most likely, installed the hook "thread wide" and not "system wide", which means that the key translation will occur only for the thread installing the hook.

In order to install it "system wide" you will need two pieces: one dll having the "hook provider" and an exe managing it. Here is a good tutorial http://www.codeproject.com/KB/system/hooksys.aspx and here an example: http://www.codeguru.com/cpp/com-tech/shell/article.php/c4509/

But: 1. Installing system wide hooks can seriously screw up you system (make sure that you forward the keys that you don't translate). 2. Please... don't create another keylogger

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