How to make sure the global keyboard hook is disabled?

I used the version of Steven Tus's global keyboard interceptor , using it in the WIN 7 environment.

It works great for a moment, and then just stops receiving keystrokes.

I increased the timeout value in regedit, but still shuts down after a while.

So, the problem is how to determine if it has been disabled, and how can I activate the hook again?

+4
source share
2 answers

There is no way to find out (from msdn ):

The hook procedure should process the message in less time than the data record specified in the LowLevelHooksTimeout value in the following registry key: HKEY_CURRENT_USER \ Control Panel \ Desktop

If the hook procedure ends, the system passes the message to the next hook. However, in Windows 7 and later, it is deleted without a call. It does not exist for the application to know if the hook is being removed.

One way you can get around this is to keep the timestamp of the last message received and use a background timer to add a new hook some time after the previous message.

In addition, to minimize this, your hook processing method should only collect the minimum required information and leave the actual data processing in a different thread.

+5
source

This is a feature! here is a description of the reason .

+2
source

Source: https://habr.com/ru/post/1438421/


All Articles