Bruno van Dooren [MVP VC++] wrote:
>>I am working on Message Hooking.I am trying to change the value of
lParam before calling CallNextHookEx() function.. and its value is
getting changed but the contents remains same.. Where as if I am able to
change wParam. For Eg: if I press any key 'S' and if I want to modify it
to 'B' by using wParam its possible.. Can u now please help me in
modifying this 'S' to 'B' using lParam?
What hook ID are you using when you install the hook function?
Afaik, keyboard monitoring via a WH_KEYBOARD or WH_KEYBOARD_LL hook
is read only. i.e.you cannot change a B to an S.
The hook functions are just for monitoring afaik.
On the other hand, you can discard a keyboard event from the keyboard
hook function but not calling CallNextHookEx, and use keybd_event to
emulate a substitute keystroke:
LRESULT CALLBACK Hook(int nCode, WPARAM wParam, LPARAM lParam)
{
if(wParam == 'S')
{
keybd_event('B', ..., 0, ...);
keybd_event('B', ..., KEYEVENTF_KEYUP, ...);
}
else
CallNextHookEx(KeyHook, nCode, wParam, lParam);
}
Be very careful, as you can cause pretty severe damage to the system if
you misuse this hook, or issue the wrong keydb_event. You could get the
control or alt key stuck forever, or get a keystroke repeating forever,
or even all keystrokes permenently disabled, after which you have to
reboot to get it fixed.
Do this at your own risk.
Tom