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.

Comments (5)
  1. henke37 says:

    And here I was patching the hotkey dispatch code on the fly in memory. Because turning of hotkeys completely in response to one event is clearly using a global solution for a local problem.

    1. Joshua says:

      I highly doubt you even got out of your process.

  2. Joshua Schaeffer says:

    We *require* the ability to enumerate registered hotkeys by process. That’s the big problem everyone has with hotkeys that MS never solved: finding out what application stole them.

  3. Joshua Schaeffer says:

    MOD_NOREPEAT = 0x4000;

    MOD_RIGHT = 0x4000;

    What’s the difference here? There’s two sets of hotkey flags that share MOD_ALT, MOD_CONTROL, and MOD_SHIFT.

  4. The MAZZTer says:

    Today I discovered apparently it’s a thing to tell other gamers in game to hold down Win+E, which I suppose pre-Win 7 repeatedly spawned Explorer windows. I guess they started catching on that ALT+F4 wasn’t going to win them the game instantly.

    https://www.reddit.com/r/gaming/comments/7aalzy/how_to_cull_the_weak_from_the_herd/dp8f7nx/

Comments are closed.

Skip to main content