Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / desktop / Win32

Change to Global Keyboard and Mouse Hooks behavior in Windows 7

4.00/5 (6 votes)
19 Jan 2011CPOL1 min read 23.7K  
This is probably why your global keyboard and mouse hooks stopped working on Windows 7
We've all written one of these apps at one time or another. You've got something that has to grab keyboard or mouse events globally for some reason. Maybe you're hotkeying something or logging what the user is doing with your app, ...

Everything worked fine under Windows XP or Vista, but now you're running into a problem where your hooks just mysteriously stop working. Maybe you're not getting any error messages, no crash, nothing in the event log, ... just nothing works!

Well, Microsoft thought it was a good idea to put a timeout in the code that calls your hook callback. I would tend to agree with them that something really did have to be done because a bad hook proc you may have written could bog down the entire system.

If you're having this little problem on Windows 7, you might want to read this[^] little blog post.

Apparently, Microsoft slipped this change into Windows 7 after its Beta was complete and just before the code went RTM. I wouldn't recommend taking this course of action in your own projects. Microsoft may have billions of dollars laying around to deal with a problem that crops up with a quick change that may be buggy like this, you probably don't.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)