Menu

#1 Adding WH_CBT hook into code

open
nobody
None
5
2006-03-14
2006-03-14
Anonymous
No

Hi,

I have added a WH_CBT hook into the pyHook cpyHook.i
file and Hookmanager.py to handle SetFocus and Activate
events because the current WH_KEYBOARD_LL callback uses
GetForegroundWindow which doesn't give the child window
with the keyboard focus but rather the parent window.

The other hooks work, like WH_KEYBOARD_LL, but with the
CBT callback routine it does not seem to enter the
callback function at all.

My register call:
...
hMod = GetModuleHandle("_cpyHook.pyd"); #_cpyHook.
pyd is the compiled Python "dll" module
...
hHooks[idHook] = SetWindowsHookEx(WH_CBT,
cCBTCallback, (HINSTANCE) hMod, 0);
...

My callback function:

LRESULT CALLBACK cCBTCallback(int code, WPARAM
wParam, LPARAM lParam) {

printf("cCBTCallback. Code = %i", code);

// decide whether or not to call the next hook
if(code < 0)
return CallNextHookEx(hHooks[WH_CBT], code,
wParam, lParam);

return CallNextHookEx(hHooks[WH_CBT], code, wParam,
lParam);
}

You wil notice that the callback function is simplistic
- I have made a more complex version but even this one
does not fire. I even tried messing with the
parameters to force an error without avail.

The call to "SetWindowsHookEx" returns what looks like
a valid handle. I need this to work across all
processes.

Please help,
Robert Gasparotto.

Discussion


Log in to post a comment.