Decrypt my World

Cryptography, Security, Debugging and more!

Global hooks getting lost on Windows 7

Global hooks getting lost on Windows 7

Rate This
  • Comments 6

Hi all,

 

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.

Regards,

 

 

Alex (Alejandro Campos Magencio)

  • thank a lot

  • cheers m8

  • 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..

  • Using RawInput method, Hooking works fine but I cannot able to block the Key events. My requirement is to block key like "VK_ENTER". In WinXP, i have used LowLevelKeyboard proc and if i want to block some key event i will return "-1" to block that key before processing by other proc in the application.

    Please give me some information to block a key in Win7.

  • Generally, I agree, but beware that an application can only register one window at a time to receive WM_INPUT meessages. If you are writing a control that needs access to mouse or keyboard input and you call RegisterRawInput from the control, this will de-regester any window that the application has already registered and you will definitely not be popular.

    John

Page 1 of 1 (6 items)
Leave a Comment
  • Please add 6 and 7 and type the answer here:
  • Post
Translate This Page