
Signature
Kind regards,
Bruno van Dooren
bruno_nos_pam_van_dooren@hotmail.com
Remove only "_nos_pam"
>>I am working on Message Hooking.I am trying to change the value of
>>lParam before calling CallNextHookEx() function.. and its value is
[quoted text clipped - 7 lines]
> 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
Bruno van Dooren [MVP VC++] - 26 Jan 2007 22:13 GMT
> 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:
Not calling CallNextHook only affects other hook functions, not regular apps
afaik.
> LRESULT CALLBACK Hook(int nCode, WPARAM wParam, LPARAM lParam)
> {
[quoted text clipped - 12 lines]
> even all keystrokes permenently disabled, after which you have to reboot
> to get it fixed.
Yeah. inserting keyboard events has the interesting side effect that your
hook function gets called.
So your keyboard hook inserts a char, for which it will get executed again,
for which it will insert...
I think that is primarily the reason why hooks are for monitoring purposes
only.
That and security of course.

Signature
Kind regards,
Bruno van Dooren
bruno_nos_pam_van_dooren@hotmail.com
Remove only "_nos_pam"
Tamas Demjen - 27 Jan 2007 01:26 GMT
> Not calling CallNextHook only affects other hook functions, not regular apps
> afaik.
I stand corrected.
I've used a keyboard hook to capture a special key combination, and
called keybd_event to issue another keystroke. I was under the
impression that I practically redefined a key. It looks like I was
completely wrong. It worked, as the original keystroke I intended to
replace did nothing at all.
Sorry for the confusion I have caused.
Tom