October 26th, 2017

How do I prevent my registered hotkey from firing repeatedly due to auto-repeat?

You can register a global hotkey with the Register­Hot­Key function, but one problem many people have is that if the user presses and holds the hotkey sequence, the hotkey will be invoked as fast as auto-repeat will let it. For some types of hotkeys, this is not desirable. How do you prevent this?

Starting in Windows 7, you can pass the MOD_NO­REPEAT flag to the Register­Hot­Key function to tell it not to generate WM_HOT­KEY messages if the hotkey activation sequences was triggered by autorepeat.

The initial press of the hotkey will generate a WM_HOT­KEY message, but the auto-repeats will not.

Topics
Code

Author

Raymond has been involved in the evolution of Windows for more than 30 years. In 2003, he began a Web site known as The Old New Thing which has grown in popularity far beyond his wildest imagination, a development which still gives him the heebie-jeebies. The Web site spawned a book, coincidentally also titled The Old New Thing (Addison Wesley 2007). He occasionally appears on the Windows Dev Docs Twitter account to tell stories which convey no useful information.

0 comments

Discussion are closed.