// ----------------------------------------------------------------------------- // Register hotkeys // ----------------------------------------------------------------------------- bool hotkeymanager_register_hotkeys(HotkeyManager* hkman) { hklist* item = hkman->hotkeys; do { // ignore hotkeys with id = -1 if (item->id != -1) { // register hotkey #ifdef _PLAT_WNDS if (RegisterHotKey(NULL, item->id, item->mod, item->vk)) #else if (xhkBindKey(hkman->hkconfig, 0, item->vk, hkconvert(item->mod), xhkKeyPress, &hotkeymanager_handle_hotkey_cb, hkman, (void*) item->id, 0) == 0) #endif // _PLAT_WNDS hklog("Successfully registered hotkey (id: %d)\n", item->id); else { hklog("WARNING: Unable to register hotkey (id: %d)\n", item->id); return false; } } // get next item item = item->next; } while (item); return true; }
int main() { vquit = 0; xhkConfig *hkconfig; hkconfig = xhkInit(NULL); // On Debian Linux, the list of XK_* keys are in: // /usr/include/X11/keysym.h // /usr/include/X11/keysymdef.h // Modifier masks in /usr/include/X11/X.h // // This is also useful for finding which keys on a keyboard are mapped to: // xbindkeys -mk xhkBindKey(hkconfig, 0, XK_P, 0, xhkKeyPress|xhkKeyRelease, &testPressRelease, 0, 0, 0); xhkBindKey(hkconfig, 0, XK_K, ControlMask | ShiftMask, xhkKeyPress, &testPress, 0, 0, 0); xhkBindKey(hkconfig, 0, XK_K, ControlMask | ShiftMask, xhkKeyPress, &testPress, 0, 0, 0); xhkBindKey(hkconfig, 0, XK_L, ControlMask | ShiftMask, xhkKeyPress, &testPress, 0, 0, 0); xhkBindKey(hkconfig, 0, XK_M, ControlMask | ShiftMask, xhkKeyRelease, &testRelease, 0, 0, 0); xhkBindKey(hkconfig, 0, XK_N, ControlMask | ShiftMask, xhkKeyPress | xhkKeyRelease, &testPressRelease, 0, 0, 0); xhkBindKey(hkconfig, 0, 1234, ControlMask | ShiftMask, xhkKeyPress, &testPress, 0, 0, 0); xhkBindKey(hkconfig, 0, XK_R, 0, xhkKeyPress | xhkKeyRelease | xhkKeyRepeat, &testPressRelease, 0, 0, 0); xhkBindKey(hkconfig, 0, XK_O, ControlMask | ShiftMask, xhkKeyPress | xhkKeyRepeat, &testPress, 0, 0, 0); xhkBindKey(hkconfig, 0, XK_O, ControlMask | ShiftMask, xhkKeyRelease | xhkKeyRepeat, &testRelease, 0, 0, 0); xhkSetRepeatThreshold(hkconfig, 10); xhkBindKey(hkconfig, 0, XK_Q, 0, 0, &setquit, "quitting now...", 0, 0); xhkBindKey(hkconfig, 0, XK_U, 0, 0, &unbind_K, 0, (void *) hkconfig, 0); printf("xhk_test: X11 Display: %p\n", xhkGetXDisplay(hkconfig)); // This loop waits on X11 keyboard events. // If you want to continue running other code while capturing the hotkeys // in the background, you'll have to run xhkPollKeys in a seperate thread. while (1) { xhkPollKeys(hkconfig, 1); if (vquit == 1) break; } xhkClose(hkconfig); return 0; }