static int get_screen_selection(void) { static KeyCode lshift_code, rshift_code; static int first_time = 1; char keys[32]; if (first_time) { first_time = 0; lshift_code = XKeysymToKeycode(GDK_WINDOW_XDISPLAY(bm.win), XStringToKeysym("Shift_L")); rshift_code = XKeysymToKeycode(GDK_WINDOW_XDISPLAY(bm.win), XStringToKeysym("Shift_R")); } XQueryKeymap(GDK_WINDOW_XDISPLAY(bm.win), keys); #if 0 if (0) { /* debug */ int i = 0; printf("lshift_code = 0x%x (index = %d, bit = %d\n", lshift_code, lshift_code >> 3, lshift_code % 8); printf("rshift_code = 0x%x (index = %d, bit = %d\n", rshift_code, rshift_code >> 3, rshift_code % 8); for (i = 0; i < (sizeof(keys) / sizeof(keys[0])); i++) { if (0 == (i % 8)) { printf("\n%2d:", i); } printf(" %2d", keys[i]); } printf("\n"); }
static void mapping_busy_key(int timeout) { int i; unsigned char keymap[32]; static unsigned int masktable[8] = { 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 }; XQueryKeymap (dpy, (char *) keymap); fprintf (stderr, "%s: please release the following keys within %d seconds:\n", ProgramName, timeout); for (i = 0; i < 256; i++) { if (keymap[i >> 3] & masktable[i & 7]) { KeySym ks = XKeycodeToKeysym (dpy, (KeyCode) i, 0); char *cp = XKeysymToString (ks); fprintf (stderr, " %s (keysym 0x%x, keycode %d)\n", cp ? cp : "UNNAMED", (unsigned int)ks, i); } } sleep (timeout); return; }
void MCScreenDC::getkeysdown(MCExecPoint &ep) { char kstring[U4L]; char km[32]; ep.clear(); MCmodifierstate = querymods(); XQueryKeymap(dpy, km); bool first = true; uint2 i; KeySym ksym; for (i = 0; i < 256; i++) { if (isKeyPressed(km, i)) { ksym = i; if (MCmodifierstate & MS_SHIFT || MCmodifierstate & MS_CAPS_LOCK) ksym = XKeycodeToKeysym(dpy, i, 1); else ksym = XKeycodeToKeysym(dpy, i, 0); if (ksym > 0) { ep.concatuint(ksym, EC_COMMA, first); first = false; } } } }
Bool listen_init(Listen* obj, Display* display, Bool modifiers, int idle_time, int poll_time) { int i; KeyCode kc; XModifierKeymap* modmap; obj->modifiers = modifiers; obj->idle_time = ((double)idle_time)/1000.0; obj->poll_time = poll_time*1000; obj->display = display; memset(obj->mask, 0xff, MTRACKD_KEYMAP_SIZE); modmap = XGetModifierMapping(obj->display); for (i = 0; i < 8 * modmap->max_keypermod; i++) { kc = modmap->modifiermap[i]; if (kc != 0) clear_bit(obj->mask, kc); } XFreeModifiermap(modmap); XQueryKeymap(obj->display, (char*)obj->current); memcpy(obj->previous, obj->current, sizeof(unsigned char)*MTRACKD_KEYMAP_SIZE); return True; }
void iupdrvGetKeyState(char* key) { char keys[32]; Display* display = (Display*)iupdrvGetDisplay(); XModifierKeymap *modMap = XGetModifierMapping(display); XQueryKeymap(display, keys); if (xCheckModifier(modMap->modifiermap, modMap->max_keypermod, ShiftMapIndex, keys)) key[0] = 'S'; else key[0] = ' '; if (xCheckModifier(modMap->modifiermap, modMap->max_keypermod, ControlMapIndex, keys)) key[1] = 'C'; else key[1] = ' '; if (xCheckModifier(modMap->modifiermap, modMap->max_keypermod, Mod1MapIndex, keys) || xCheckModifier(modMap->modifiermap, modMap->max_keypermod, Mod5MapIndex, keys)) key[2] = 'A'; else key[2] = ' '; if (xCheckModifier(modMap->modifiermap, modMap->max_keypermod, Mod4MapIndex, keys)) key[3] = 'Y'; else key[3] = ' '; key[4] = 0; XFreeModifiermap(modMap); }
static enum KeyboardActivity keyboard_activity(Display * display) { static unsigned char old_key_state[KEYMAP_SIZE]; unsigned char key_state[KEYMAP_SIZE]; int i; int ret = ActivityNone; XQueryKeymap(display, (char *) key_state); for (i = 0; i < KEYMAP_SIZE; i++) { if ((key_state[i] & ~old_key_state[i]) & keyboard_mask[i]) { ret = ActivityNew; break; } } if (ignore_modifier_combos) { for (i = 0; i < KEYMAP_SIZE; i++) { if (key_state[i] & ~keyboard_mask[i]) { if (old_key_state[i] & ~keyboard_mask[i]) ret = ActivityNone; else ret = ActivityReset; break; } } } for (i = 0; i < KEYMAP_SIZE; i++) old_key_state[i] = key_state[i]; return ret; }
i32 xwl_pollevent( xwl_event_t *event ) { #ifdef _WIN32 MSG msg; while ( PeekMessage( &msg, 0, 0, 0, PM_REMOVE ) ) { TranslateMessage( &msg ); DispatchMessage( &msg ); } #endif #if LINUX XEvent ev; i32 i; xwl_window_handle_t *wh = 0; XEvent lastKeyReleaseEvent; for( i = 0; i < XWL_MAX_WINDOW_HANDLES; ++i ) { wh = &xwl_windowHandles[i]; if ( wh->handle.handle != 0 ) { while (XCheckIfEvent( currentDisplay, &ev, &CheckEvent, wh->handle.handle) ) { if ((ev.type == KeyPress) || (ev.type == KeyRelease) ) { if ( ev.xkey.keycode < 256 ) { // To detect if it is a repeated key event, we check the current state of the key. // - If the state is "down", KeyReleased events must obviously be discarded. // - KeyPress events are a little bit harder to handle: they depend on the EnableKeyRepeat state, // and we need to properly forward the first one. char keys[32]; XQueryKeymap(currentDisplay, keys); if (keys[ev.xkey.keycode >> 3] & (1 << (ev.xkey.keycode % 8))) { // KeyRelease event + key down = repeated event --> discard if (ev.type == KeyRelease) { lastKeyReleaseEvent = ev; continue; } // KeyPress event + key repeat disabled + matching KeyRelease event = repeated event --> discard if ((ev.type == KeyPress) && (lastKeyReleaseEvent.xkey.keycode == ev.xkey.keycode) && (lastKeyReleaseEvent.xkey.time == ev.xkey.time)) { continue; } } } } ProcessEvent( ev, wh ); } } }
void Input::PollKeyboard(char* keyboardState) { #if defined(_WIN32) GetKeyboardState((PBYTE) keyboardState); #elif defined(X11) XQueryKeymap(display, keyboardState); #endif }
bool GetXlibKeyState(int key) { if(CurrentXDisplay == NULL) return false; KeySym ks = 0; if(key >= eRENDERDOC_Key_A && key <= eRENDERDOC_Key_Z) ks = key; if(key >= eRENDERDOC_Key_0 && key <= eRENDERDOC_Key_9) ks = key; switch(key) { case eRENDERDOC_Key_Divide: ks = XK_KP_Divide; break; case eRENDERDOC_Key_Multiply: ks = XK_KP_Multiply; break; case eRENDERDOC_Key_Subtract: ks = XK_KP_Subtract; break; case eRENDERDOC_Key_Plus: ks = XK_KP_Add; break; case eRENDERDOC_Key_F1: ks = XK_F1; break; case eRENDERDOC_Key_F2: ks = XK_F2; break; case eRENDERDOC_Key_F3: ks = XK_F3; break; case eRENDERDOC_Key_F4: ks = XK_F4; break; case eRENDERDOC_Key_F5: ks = XK_F5; break; case eRENDERDOC_Key_F6: ks = XK_F6; break; case eRENDERDOC_Key_F7: ks = XK_F7; break; case eRENDERDOC_Key_F8: ks = XK_F8; break; case eRENDERDOC_Key_F9: ks = XK_F9; break; case eRENDERDOC_Key_F10: ks = XK_F10; break; case eRENDERDOC_Key_F11: ks = XK_F11; break; case eRENDERDOC_Key_F12: ks = XK_F12; break; case eRENDERDOC_Key_Home: ks = XK_Home; break; case eRENDERDOC_Key_End: ks = XK_End; break; case eRENDERDOC_Key_Insert: ks = XK_Insert; break; case eRENDERDOC_Key_Delete: ks = XK_Delete; break; case eRENDERDOC_Key_PageUp: ks = XK_Prior; break; case eRENDERDOC_Key_PageDn: ks = XK_Next; break; case eRENDERDOC_Key_Backspace: ks = XK_BackSpace; break; case eRENDERDOC_Key_Tab: ks = XK_Tab; break; case eRENDERDOC_Key_PrtScrn: ks = XK_Print; break; case eRENDERDOC_Key_Pause: ks = XK_Pause; break; default: break; } if(ks == 0) return false; KeyCode kc = XKeysymToKeycode(CurrentXDisplay, ks); char keyState[32]; XQueryKeymap(CurrentXDisplay, keyState); int byteIdx = (kc / 8); int bitMask = 1 << (kc % 8); uint8_t keyByte = (uint8_t)keyState[byteIdx]; return (keyByte & bitMask) != 0; }
bool CXWindowsPrimaryScreen::isLockedToScreen() const { CDisplayLock display(m_screen); // query the pointer to get the button state Window root, window; int xRoot, yRoot, xWindow, yWindow; unsigned int state; if (XQueryPointer(display, m_window, &root, &window, &xRoot, &yRoot, &xWindow, &yWindow, &state)) { if ((state & (Button1Mask | Button2Mask | Button3Mask | Button4Mask | Button5Mask)) != 0) { LOG((CLOG_DEBUG "locked by mouse button")); return true; } } // get logical keyboard state char keyMap[32]; memset(keyMap, 0, sizeof(keyMap)); XQueryKeymap(display, keyMap); // locked if any key is down for (unsigned int i = 0; i < sizeof(keyMap); ++i) { if (keyMap[i] != 0) { for (unsigned int j = 0; j < 8; ++j) { if ((keyMap[i] & (1 << j)) != 0) { const KeyCode keycode = 8 * i + j; const KeySym keysym = XKeycodeToKeysym(display, keycode, 0); // if any key is half-duplex then it'll be down when // toggled on but shouldn't count as a reason to lock // to the screen. if (m_numLockHalfDuplex && keysym == XK_Num_Lock) { continue; } if (m_capsLockHalfDuplex && keysym == XK_Caps_Lock) { continue; } // non-half-duplex key down char* name = XKeysymToString(keysym); if (name == NULL) { LOG((CLOG_DEBUG "locked by keycode %d", keycode)); } else { LOG((CLOG_DEBUG "locked by \"%s\"", name)); } return true; } } } } // not locked return false; }
/* Input: Display, Array of keycodes, length of both arrays Output: Array of ints. (no bools because sizeof(bool,vala) != sizeof(bool, stdbool.h) */ void checkModifier(Display* display, int* keycodes, int nkeycodes, int* pressed){ XQueryKeymap(display, keymap); int i; for (i=0; i<nkeycodes; i++) { pressed[i] = keyPressed(keycodes[i], keymap)?1:0; //printf("%i Pressed? %i\n", keycodes[i], (pressed[i]) ); } }
static gboolean is_key_released (long code) { char keys[32]; int down; XQueryKeymap (spi_get_display (), keys); down = BIT (keys, code); return (down == 0); }
Bool is_key_pressed(Display *display, KeySym sym) { // determine if the key "sym" is pressed or not // this routine from "Introduction to the X Window System", 1989, p. 388 KeyCode code = XKeysymToKeycode(display, sym); if (code == NoSymbol) return false; char key_vector[32]; XQueryKeymap(display, key_vector); return (key_vector[code/8] >> (code&7)) & 1; }
void poll(vector<HID::Device*>& devices) { char state[32]; XQueryKeymap(display, state); for(unsigned n = 0; n < keys.size(); n++) { bool value = state[keys[n].keycode >> 3] & (1 << (keys[n].keycode & 7)); assign(n, value); } devices.append(&hid); }
static void x_input_poll(void *data) { x11_input_t *x11 = (x11_input_t*)data; if (video_focus_func()) XQueryKeymap(x11->display, x11->state); else memset(x11->state, 0, sizeof(x11->state)); x_input_poll_mouse(x11); input_joypad_poll(x11->joypad); }
void XWindowsKeyState::pollPressedKeys(KeyButtonSet& pressedKeys) const { char keys[32]; XQueryKeymap(m_display, keys); for (UInt32 i = 0; i < 32; ++i) { for (UInt32 j = 0; j < 8; ++j) { if ((keys[i] & (1u << j)) != 0) { pressedKeys.insert(8 * i + j); } } } }
bool InputDeviceProvider_X11Keyboard::get_keycode(int keycode) const { // Ignore all key events when we don't have focus if(!window->has_focus()) return false; char keyboard_state[32]; InputCode code = (InputCode)XKeysymToKeycode(window->get_display(), keycode); XQueryKeymap(window->get_display(), keyboard_state); return keyboard_state[code/8] & (1 << code%8); }
// check whether our modkeys are currently pressed int modkey_is_down() { char keys[32]; int i, j; XQueryKeymap(display, keys); for (i = 0; i < 32; i++) { if (!keys[i]) continue; unsigned int bits = keys[i]; for (j = 0; j < 8; j++) if (bits & 1<<j && keycode_is_mod((i*8)+j)) return 1; } return 0; }
bool InputUtils::Update(Display *display) { //Assign the X-Display xDisplay = display; //Update the bit array of what keys are down if(display != NULL) { XQueryKeymap(xDisplay,keyState); return true; } return false; }
/* This name doesn't really cover this function, since it also sets up mouse and keyboard. This is done over here, since on most display targets the mouse and keyboard can't be setup before the display has. */ int xf86_dga2_open_display(int reopen) { int i; /* only have todo the fork's the first time we go DGA, otherwise people who do a lott of dga <-> window switching will get a lott of children */ static int first_time = 1; xf86_dga_first_click = 0; if (reopen) { sysdep_display_effect_close(); return xf86_dga2_set_mode(); } window = RootWindow(display,xf86ctx.screen); if (first_time) { if(xf86_dga_vidmode_setup_mode_restore()) return 1; first_time = 0; } /* HACK HACK HACK, keys get stuck when they are pressed when XDGASetMode is called, so wait for all keys to be released */ do { char keys[32]; XQueryKeymap(display, keys); for (i=0; (i<32) && (keys[i]==0); i++) {} } while(i<32); /* Grab keyb and mouse ! */ if(xinput_open(1, 0)) { fprintf(stderr,"XGrabKeyboard failed\n"); return 1; } if(xf86_dga2_set_mode()) return 1; /* setup the colormap */ xf86ctx.cmap = XDGACreateColormap(display, xf86ctx.screen, xf86ctx.device, AllocNone); XDGAInstallColormap(display,xf86ctx.screen,xf86ctx.cmap); return 0; }
bool KeyboardMouse::UpdateInput() { XQueryKeymap(m_display, m_state.keyboard); int root_x, root_y, win_x, win_y; Window root, child; XQueryPointer(m_display, m_window, &root, &child, &root_x, &root_y, &win_x, &win_y, &m_state.buttons); // update mouse cursor XWindowAttributes win_attribs; XGetWindowAttributes(m_display, m_window, &win_attribs); // the mouse position as a range from -1 to 1 m_state.cursor.x = (float)win_x / (float)win_attribs.width * 2 - 1; m_state.cursor.y = (float)win_y / (float)win_attribs.height * 2 - 1; return true; }
bool wxGetKeyState(wxKeyCode key) { wxASSERT_MSG(key != WXK_LBUTTON && key != WXK_RBUTTON && key != WXK_MBUTTON, wxT("can't use wxGetKeyState() for mouse buttons")); Display *pDisplay = (Display*) wxGetDisplay(); int iKey = wxCharCodeWXToX(key); int iKeyMask = 0; Window wDummy1, wDummy2; int iDummy3, iDummy4, iDummy5, iDummy6; unsigned int iMask; KeyCode keyCode = XKeysymToKeycode(pDisplay,iKey); if (keyCode == NoSymbol) return false; if ( IsModifierKey(iKey) ) // If iKey is a modifier key, use a different method { XModifierKeymap *map = XGetModifierMapping(pDisplay); wxCHECK_MSG( map, false, wxT("failed to get X11 modifiers map") ); for (int i = 0; i < 8; ++i) { if ( map->modifiermap[map->max_keypermod * i] == keyCode) { iKeyMask = 1 << i; } } XQueryPointer(pDisplay, DefaultRootWindow(pDisplay), &wDummy1, &wDummy2, &iDummy3, &iDummy4, &iDummy5, &iDummy6, &iMask ); XFreeModifiermap(map); return (iMask & iKeyMask) != 0; } // From the XLib manual: // The XQueryKeymap() function returns a bit vector for the logical state of the keyboard, // where each bit set to 1 indicates that the corresponding key is currently pressed down. // The vector is represented as 32 bytes. Byte N (from 0) contains the bits for keys 8N to 8N + 7 // with the least-significant bit in the byte representing key 8N. char key_vector[32]; XQueryKeymap(pDisplay, key_vector); return key_vector[keyCode >> 3] & (1 << (keyCode & 7)); }
bool ofGetModifierPressed(unsigned int mod) { unsigned int t = 0; //return false; Display* disp = glXGetCurrentDisplay(); char key_map_stat[32]; XQueryKeymap(disp, key_map_stat); if ((OF_KEY_ALT & mod) == OF_KEY_ALT){ const KeyCode alt_l = XKeysymToKeycode(disp,XK_Alt_L); const KeyCode alt_r = XKeysymToKeycode(disp,XK_Alt_R); return (((key_map_stat[alt_l >> 3] >> (alt_l & 7)) & 1) ||((key_map_stat[alt_r >> 3] >> (alt_r & 7)) & 1)); } if ((OF_KEY_CONTROL & mod) == OF_KEY_CONTROL){ const KeyCode control_l = XKeysymToKeycode(disp,XK_Control_L); const KeyCode control_r = XKeysymToKeycode(disp,XK_Control_R); return (((key_map_stat[control_l >> 3] >> (control_l & 7)) & 1) ||((key_map_stat[control_r >> 3] >> (control_r & 7)) & 1)); } if((OF_KEY_SHIFT & mod) == OF_KEY_SHIFT){ const KeyCode shift_l = XKeysymToKeycode(disp,XK_Shift_L); const KeyCode shift_r = XKeysymToKeycode(disp,XK_Shift_R); return (((key_map_stat[shift_l >> 3] >> (shift_l & 7)) & 1) ||((key_map_stat[shift_r >> 3] >> (shift_r & 7)) & 1)); } if ((OF_KEY_SPECIAL & mod) == OF_KEY_SPECIAL){ const KeyCode control_l = XKeysymToKeycode(disp,XK_Super_L); const KeyCode control_r = XKeysymToKeycode(disp,XK_Super_R); return (((key_map_stat[control_l >> 3] >> (control_l & 7)) & 1) ||((key_map_stat[control_r >> 3] >> (control_r & 7)) & 1)); } return false; }
static Bool listen_activity(Listen* obj) { int i; Bool res = False; XQueryKeymap(obj->display, (char*)obj->current); for (i = 0; i < MTRACKD_KEYMAP_SIZE; i++) { if ((obj->current[i] & ~obj->previous[i]) & obj->mask[i]) { res = True; break; } else if (obj->modifiers && (obj->current[i] & ~obj->mask[i])) { res = True; break; } } memcpy(obj->previous, obj->current, sizeof(unsigned char)*MTRACKD_KEYMAP_SIZE); return res; }
void tick(const xen::TickContext& tick){ ////////////////////////////////////////////////////////////////// // Update the cached state of the keyboard XQueryKeymap(xwn::state->display, xwn::state->keymap_state); ////////////////////////////////////////////////////////////////// // Update modifier key state // :TODO: we should really update this in response to actual events as well, // but issue is that the press or release of one of the keys does not // guarentee state (eg, if holding both shift keys simultaneously) // This is rare, but possible... xen::setBitState(xwn::state->modifier_keys, (xen::ModifierKeyState)xen::ModifierKeys::Control, xwn::isKeyPressed(xen::Key::RCtrl) || xwn::isKeyPressed(xen::Key::LCtrl)); xen::setBitState(xwn::state->modifier_keys, (xen::ModifierKeyState)xen::ModifierKeys::Alt, xwn::isKeyPressed(xen::Key::RAlt) || xwn::isKeyPressed(xen::Key::LAlt)); xen::setBitState(xwn::state->modifier_keys, (xen::ModifierKeyState)xen::ModifierKeys::Shift, xwn::isKeyPressed(xen::Key::RShift) || xwn::isKeyPressed(xen::Key::LShift)); xen::setBitState(xwn::state->modifier_keys, (xen::ModifierKeyState)xen::ModifierKeys::System, xwn::isKeyPressed(xen::Key::RSystem) || xwn::isKeyPressed(xen::Key::LSystem)); ////////////////////////////////////////////////////////////////// // Process window events XEvent event; for(uint i = 0; i < xwn::state->windows.size; ++i){ xen::Window* win = &xwn::state->windows[i]; while(XCheckIfEvent(xwn::state->display, &event, &checkEventMatchesWindow, reinterpret_cast<XPointer>(win->xwindow)) ){ processWindowEvent(win, &event); } } //while(XPending(xwn::state->display)){ // XNextEvent(xwn::state->display, &event); // printf("Found pending event\n"); //} }
void* gstate_update_func(void* arg) { KeyboardUGenGlobalState* gstate; Window r; struct timespec requested_time , remaining_time; requested_time.tv_sec = 0; requested_time.tv_nsec = 17000 * 1000; d = XOpenDisplay ( NULL ); if (!d) return 0; gstate = &gKeyStateGlobals; for (;;) { XQueryKeymap ( d , (char *) (gstate->keys) ); nanosleep ( &requested_time , &remaining_time ); } return 0; }
void gstate_update_func() { Window r; struct timespec requested_time , remaining_time; // NOTE: should not be required as this is the only thread accessing the x11 API // but omitting seems to cause troubles. XInitThreads(); d = XOpenDisplay ( NULL ); if (!d) return; Window rep_root, rep_child; XWindowAttributes attributes; int rep_rootx, rep_rooty ; unsigned int rep_mask; int dx, dy; float r_width; float r_height; r = DefaultRootWindow ( d ); XGetWindowAttributes ( d, r, &attributes ); r_width = 1.0 / (float)attributes.width; r_height = 1.0 / (float)attributes.height; while ( inputThreadRunning.load( std::memory_order_relaxed ) ) { XQueryKeymap ( d , (char *) (gKeyStateGlobals.keys) ); XQueryPointer ( d, r, &rep_root, &rep_child, &rep_rootx, &rep_rooty, &dx, &dy, &rep_mask); gMouseUGenGlobals.mouseX = (float)dx * r_width; gMouseUGenGlobals.mouseY = 1.f - ( (float)dy * r_height ); gMouseUGenGlobals.mouseButton = (bool) ( rep_mask & Button1Mask ); std::this_thread::sleep_for( std::chrono::milliseconds( 17 ) ); } }
bool ManglerSettings::settingsPTTKeyDetect(void) {/*{{{*/ char pressed_keys[32]; Glib::ustring ptt_keylist; GdkWindow *rootwin = gdk_get_default_root_window(); // TODO: window close event needs to set isDetectingKey if (!isDetectingKey) { return false; } /* * Query the X keymap and get a list of all the keys are pressed. Convert * keycodes to keysyms to keynames and build a human readable string that * will be the actual value stored in the settings file */ XQueryKeymap(GDK_WINDOW_XDISPLAY(rootwin), pressed_keys); for (int ctr = 0; ctr < 256; ctr++) { if ((pressed_keys[ctr >> 3] >> (ctr & 0x07)) & 0x01) { char *keystring = XKeysymToString(XKeycodeToKeysym(GDK_WINDOW_XDISPLAY(rootwin), ctr, 0)); if (keystring == NULL) continue; std::string keyname = keystring; if (keyname.length() > 1) { ptt_keylist.insert(0, "<" + keyname + ">" + (ptt_keylist.empty() ? "" : "+")); } else { keyname[0] = toupper(keyname[0]); ptt_keylist.append((ptt_keylist.empty() ? "" : "+") + keyname); } } } builder->get_widget("settingsPTTKeyValueLabel", label); if (ptt_keylist.empty()) { label->set_markup(PTT_KEY_SET); } else { label->set_text(ptt_keylist); } return(true); }/*}}}*/
void simulateKeyPress(Display *display, const QList<int> &modCodes, unsigned int key) { // Find modifiers to release. static QList<int> mods = QList<int>() << XK_Shift_L << XK_Shift_R << XK_Control_L << XK_Control_R << XK_Meta_L << XK_Meta_R << XK_Alt_L << XK_Alt_R << XK_Super_L << XK_Super_R << XK_Hyper_L << XK_Hyper_R; char keyMap[32]; XQueryKeymap(display, keyMap); QList<KeyCode> modsToRelease; foreach (int mod, mods) { if ( isPressed(XKeysymToKeycode(display, mod), keyMap) ) modsToRelease << XKeysymToKeycode(display, mod); } // Release currently pressed modifiers. foreach (KeyCode mod, modsToRelease) FakeKeyEvent(display, mod, False); simulateModifierKeyPress(display, modCodes, True); KeyCode keyCode = XKeysymToKeycode(display, key); FakeKeyEvent(display, keyCode, True); FakeKeyEvent(display, keyCode, False); simulateModifierKeyPress(display, modCodes, False); // Press modifiers again. foreach (KeyCode mod, modsToRelease) FakeKeyEvent(display, mod, True); XSync(display, False); }
bool Sys_ShiftDown(){ #ifdef _WIN32 return ( GetKeyState( VK_SHIFT ) & 0x8000 ) != 0; #endif #if defined ( __linux__ ) || defined ( __APPLE__ ) char keys[32]; int x; XQueryKeymap( GDK_DISPLAY(), keys ); x = XKeysymToKeycode( GDK_DISPLAY(), XK_Shift_L ); if ( keys[x / 8] & ( 1 << ( x % 8 ) ) ) { return true; } x = XKeysymToKeycode( GDK_DISPLAY(), XK_Shift_R ); if ( keys[x / 8] & ( 1 << ( x % 8 ) ) ) { return true; } return false; #endif }