Some time ago a customer of mine reported the following issue with SetWindowsHookEx API:
Their application had global hooks to monitor for both keyboard and mouse input. On Windows 7, and under high CPU usage, those hooks were getting lost. They tried several things to solve the issue, without success: adjust registry setting "Control Panel\Desktop\LowLevelKeyboardProc" to 10000 (10sec), restart the hooks every X minutes (with UnhookWindowsHookEx and SetWindowsHookEx), etc. At the end, they had to restart the app to reactivate the hooks.
After some research I found out the following:
On Windows 7 we have to make sure that the callback function of the hook can return in less than LowLevelHooksTimeout, which is 300 ms. And we allow for the application to be timed out 10 times when processing the hook callback message. If it times out an 11th time, Windows will unhook the application from the hook chain. This is a by design feature and it was added in Win7 RTM.
My recommendation is that low level hooks should be avoided whenever possible. If you are monitoring keystrokes (and not trying to block them), you can get the keyboard input via Raw Input. This is lighter weight than hooks, won’t affect other apps’ responsiveness, and won’t be turned off if the app isn’t responsive.
My customer got rid of the hooks and used Raw Input instead with success. I hope this helps you too.
Alex (Alejandro Campos Magencio)
thank a lot
It was just what i'm looking for! Thanks!
Thanks a lot and i have doubt on Global hooks,
Is is possible to run 32bit CBT hook and 64bit mouse hook together on windows 7(64bit) ?
Because am getting issue on that. i have installed 32bit hook and 64bit hook. after installation of 64bit hook, if i start any 32bit window application, it is not responding and unhooked also. if i kill that 64bit hook process, 32bit hook start to work.
please give me some information regarding this..