public void when_key_press (KeyPress event) {
    keycode = event.detail ();
    int keystate = event.state ();
    keysym = display.input.keycode_to_keysym (keycode, keystate);

    shift_down = (keystate & Input.SHIFT_MASK) != 0;
    control_down = (keystate & Input.CONTROL_MASK) != 0;
    meta_down = (keystate & Input.META_MASK) != 0;    
    alt_down = (keystate & Input.ALT_MASK) != 0;    
    super_down = (keystate & 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 RuntimeException ("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;
    }
  }