public void send_key(Window window, int keysym) { bool capital = keysym >= 'A' && keysym <= 'Z'; // keysym of corresponding small letter int small_keysym = !capital ? keysym : keysym + ('a' - 'A'); KeyPress key_event = new KeyPress (display); key_event.set_window (window); key_event.set_detail (display.input.keysym_to_keycode (small_keysym)); if (capital) key_event.set_state (gnu.x11.Input.SHIFT_MASK); window.send_event (false, Event.NO_EVENT_MASK, key_event); }
protected override void exec() { if (help_option) return; Console.WriteLine ("Sending a synthetic KeyPress..."); KeyPress key_event = new KeyPress (display); key_event.set_window (window); key_event.set_detail (display.input.keysym_to_keycode ('t')); window.send_event (false, Event.NO_EVENT_MASK, key_event); Console.WriteLine ("Sending a synthetic ButtonPress to exit..."); ButtonPress button_event = new ButtonPress (display); key_event.set_window (window); window.send_event (false, Event.NO_EVENT_MASK, button_event); while (!exit_now) { dispatch_event (); Console.WriteLine ("Received: " + evt); } display.close (); }
public void when_key_press(KeyPress evt) { keycode = evt.detail (); int keystate = evt.state (); keysym = display.input.keycode_to_keysym (keycode, keystate); shift_down = (keystate & gnu.x11.Input.SHIFT_MASK) != 0; control_down = (keystate & gnu.x11.Input.CONTROL_MASK) != 0; meta_down = (keystate & gnu.x11.Input.META_MASK) != 0; alt_down = (keystate & gnu.x11.Input.ALT_MASK) != 0; base_down = (keystate & gnu.x11.Input.SUPER_MASK) != 0; if (!system_key_pressed && !focus_key_pressed) { int status = root.grab_keyboard (false, Window.ASYNCHRONOUS, Window.ASYNCHRONOUS, Display.CURRENT_TIME); if (status != Window.SUCCESS) throw new Exception ("Failed to grab keyboard"); focus_key_pressed = keysym == Misc.TAB; system_key_pressed = !focus_key_pressed; if (system_key_pressed) return; // if tab (see #next_client) focus_base = focus; focus_so_far.Clear (); if (focus_base.class_hint != null) focus_so_far.Add (focus.class_hint.res_class ()); } if (focus_key_pressed) { if (keysym == Misc.ESCAPE) { // abort-switch-focus focus_key_pressed = false; set_focus (focus_base, true); } else if (keysym == Misc.TAB) key_switch_focus (); return; } if (key_process ()) { // done display.input.ungrab_keyboard (); system_key_pressed = false; prefix0 = prefix1 = 0; argument = 0; argument_negative = false; argument_present = false; } }