First, you need to register a "system-wide" hot key with RegisterHotKey function. It works even if your application is minimized, not focused, or hidden.
RegisterHotKey(hWnd, KEY_ID, MOD_CONTROL | MOD_SHIFT, VK_UP);
// check for errors, the function will fail if the hot key is already registered
hWnd
is the handle of the window that will receive WM_HOTKEY message. KEY_ID
is the identifier for the hot key. MOD_CONTROL | MOD_SHIFT
for both Ctrl+Shift. VK_UP
for the Up arrow key.
Second, you need to handle the WM_HOTKEY message in your window procedure.
LRESULT CALLBACK WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
switch (uMsg) {
...
WM_HOTKEY:
// handle the hot key here
...
}
}
If your application does not have a window and hWnd
is NULL, then you need to handle the WM_HOTKEY in your message loop.
MSG msg = {0};
while (GetMessage(&msg, NULL, 0, 0) != 0)
{
if (msg.message == WM_HOTKEY) {
// handle the hot key here
}
}