2

is it possible to edit a keystroke using a winapi keyboard hook? well, not neccesary a keyboard hook but something like it..

i wanna do something like this:

user presses key 'A'

my function adds 1 to the virtual keycode (just an example)

the 'A' becomes an 'B'

and the 'B' is sent to the destination application

thanks!

shuwo
  • 21
  • 2

3 Answers3

1

First, you need a Keyboardhook. You install a filter and the filter function receives the virtual-key code and the state of the keyboard at the time of the keyboard hook. Then you can change the virtual-key code.

Additional Links:

http://msdn.microsoft.com/en-us/library/ms644990(VS.85).aspx

http://msdn.microsoft.com/en-us/library/ms644984(VS.85).aspx

Tobias Langner
  • 10,634
  • 6
  • 46
  • 76
  • if i understand you correct, i've already tried this. do you mean just to change the virtal code in the KBDLLHOOKSTRUCT received in the keyboardproc? – shuwo Oct 27 '09 at 15:05
  • Yes, it works very well in exactly that way (I've done such a thing once). Note that you should have a _really_ good reason for doing that, as most people will find it objective if not malicious, and at least if you install a system-wide hook, antivirus software will likely raise an alert, too (application-wide hook does not seem to raise alerts, at least here). – Damon Mar 22 '11 at 09:15
0

I think you can do it by eating up the keystroke entered by user by applying keyboard hook. and generating key_event of the character you want.

Ashish
  • 8,441
  • 12
  • 55
  • 92
0

You can't change the virtual key value in the KBDLLHOOKSTRUCT directly. Instead, return 1 in the hook function after you sendmessage with your modified virtual key value.

BenMorel
  • 34,448
  • 50
  • 182
  • 322
MikeZoo
  • 23
  • 5