Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Global hotkey with WIN32 API?

I've been able to set local hotkeys like this

 RegisterHotKey(hwndDlg, 100, MOD_ALT | MOD_CONTROL, 'S');

How can I set the hotkey to be global? I want it to be there even when my window is hidden.

like image 336
Mars Avatar asked Nov 30 '09 16:11

Mars


3 Answers

I solved it myself but thanks for your reply here's what was wrong...

ShowWindow(hwndDlg, SW_HIDE);
RegisterHotKey(hwndDlg, 100, MOD_ALT | MOD_CONTROL, 'S');

if you register the hotkey first then hide the window... it ignores the hotkey for some reason... oh well.. it's working now :)

like image 88
Mars Avatar answered Nov 19 '22 15:11

Mars


http://msdn.microsoft.com/ru-RU/library/windows/desktop/ms646309(v=vs.85).aspx

hWnd [in, optional]

Type: HWND

<...> If this parameter is NULL, WM_HOTKEY messages are posted to the message queue of the calling thread and must be processed in the message loop.

That is a better way for registering global hotkeys.

like image 45
Yan Sultanov Avatar answered Nov 19 '22 13:11

Yan Sultanov


It desn't matter if your window is visible or not. You should not use a hWnd you plan to destory (like a dialog). Create a separate (invisible) window if you have no other suitable window.

like image 4
Dan Byström Avatar answered Nov 19 '22 14:11

Dan Byström