Global hotkey release (keyup)? (WIN32 API)
Asked Answered
B

2

8

Is there a way to notice the release of a hot-key button registered with RegisterHotKey?

I get a WM_HOTKEY message every time I press the hot-key but I need to know when the key was released

Bilyeu answered 9/1, 2012 at 3:29 Comment(0)
G
5

There is no specific notification for that specific action. You will have to write a DLL that implements a global keyboard hook via SetWindowsHookEx(), then you will receive individual keypress up/down notifications and can match them up to your WM_HOTKEY notifications as needed.

Goethe answered 9/1, 2012 at 3:36 Comment(0)
B
7

Use RegisterHotkey to detect the key going down, then use polling with GetAsyncKeyState until the key is no longer down. This avoids the complexity of SetWindowsHookEx and the polling is generally acceptable since it is only done while the hotkey is being held down.

Bouffant answered 18/12, 2016 at 22:54 Comment(5)
IMHO the better solution if you only have one or a few hotkeysExaminee
Calling GetKeyState should also work and is preferred over GetAsyncKeyState.Geulincx
@Geulincx Why is it preferred?Bouffant
calling GetAsyncKeyState too often can be detected by antivirus software as a keylogger.Geulincx
Ah, people who use antivirus garbage deserve such things.Bouffant
G
5

There is no specific notification for that specific action. You will have to write a DLL that implements a global keyboard hook via SetWindowsHookEx(), then you will receive individual keypress up/down notifications and can match them up to your WM_HOTKEY notifications as needed.

Goethe answered 9/1, 2012 at 3:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.