Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Global hotkey release (keyup)? (WIN32 API)

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

like image 883
Crackoder Avatar asked Jan 09 '12 03:01

Crackoder


2 Answers

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.

like image 70
Remy Lebeau Avatar answered Nov 17 '22 21:11

Remy Lebeau


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.

like image 45
NateS Avatar answered Nov 17 '22 20:11

NateS