void ProcessEvents() { IntPtr display = API.DefaultDisplay; using (new XLock(display)) { Functions.XQueryKeymap(display, keys); for (int keycode = 8; keycode < 256; keycode++) { bool pressed = (keys[keycode >> 3] >> (keycode & 0x07) & 0x01) != 0; Key key; for (int mod = 0; mod < KeysymsPerKeycode; mod++) { IntPtr keysym = Functions.XKeycodeToKeysym(display, (byte)keycode, mod); if (keysym != IntPtr.Zero && keymap.TryGetValue((XKey)keysym, out key)) { if (pressed) { state.EnableBit((int)key); } else { state.DisableBit((int)key); } break; } } } } }
void ToggleKey(ref XKeyEvent keyEvent, bool pressed) { int keysym = (int)API.XLookupKeysym(ref keyEvent, 0); int keysym2 = (int)API.XLookupKeysym(ref keyEvent, 1); Key tkKey; if (keymap.TryGetValue(keysym, out tkKey)) { Keyboard.Set(tkKey, pressed); } else if (keymap.TryGetValue(keysym2, out tkKey)) { Keyboard.Set(tkKey, pressed); } else { Debug.Print("KeyCode {0} (Keysym: {1}, {2}) not mapped.", e.KeyEvent.keycode, keysym, keysym2); } }