Package com.jetbrains

Interface Keyboard


@Service @Provided public interface Keyboard
JBR API to inspect additional properties of AWT key events and keyboards.
  • Method Details

    • getKeyEventUSKeyCode

      int getKeyEventUSKeyCode(KeyEvent event)
      Inspect, which physical key was pressed on the keyboard, regardless of the active logical keyboard layout. The list of virtual key codes is found in KeyEvent. The values for the same scan code may depend on the physical keyboard layout type (ANSI, ISO or JIS)
      Parameters:
      event - JBR-generated event to inspect. This must either be a KeyEvent.KEY_PRESSED or a KeyEvent.KEY_RELEASED event
      Returns:
      The key code of the corresponding key on the standard QWERTY layout
      Throws:
      UnsupportedOperationException - Inspecting this property is not supported on the current platform, or the event was not generated by JBR
      IllegalArgumentException - Passed KeyEvent is not of a valid type
    • getKeyEventDeadKeyCode

      int getKeyEventDeadKeyCode(KeyEvent event)
      Get the dead key code for the event. If the key (without modifiers) is dead on the current layout (current ASCII-capable layout if national keyboard layout support is active), then return the corresponding dead key code, otherwise return KeyEvent.VK_UNDEFINED. The dead key code will either be a VK_DEAD_ keycode, or an extended key code for dead keys that do not have the corresponding named key code.
      Parameters:
      event - JBR-generated event to inspect. This must either be a KeyEvent.KEY_PRESSED or a KeyEvent.KEY_RELEASED event
      Returns:
      The dead key code if the key is dead, or KeyEvent.VK_UNDEFINED otherwise
      Throws:
      UnsupportedOperationException - Inspecting this property is not supported on the current platform, or the event was not generated by JBR
      IllegalArgumentException - Passed KeyEvent is not of a valid type
    • getKeyEventDeadKeyStroke

      int getKeyEventDeadKeyStroke(KeyEvent event)
      Get the dead keystroke code for the event. If the keystroke (with modifiers) is dead on the current (not necessarily ASCII-capable) keyboard layout, return the corresponding dead key code for this keystroke, otherwise return KeyEvent.VK_UNDEFINED. The dead key code will either be a VK_DEAD_ keycode, or an extended key code for dead keystrokes that do not have the corresponding named key code.
      Parameters:
      event - JBR-generated event to inspect. This must either be a KeyEvent.KEY_PRESSED or a KeyEvent.KEY_RELEASED event
      Returns:
      The dead keystroke code if the key is dead, or KeyEvent.VK_UNDEFINED otherwise
      Throws:
      UnsupportedOperationException - Inspecting this property is not supported on the current platform, or the event was not generated by JBR
      IllegalArgumentException - Passed KeyEvent is not of a valid type
    • getKeyEventCharacters

      String getKeyEventCharacters(KeyEvent event)
      Get the characters that this key event has produced. For KeyEvent.KEY_TYPED it's equivalent to KeyEvent.getKeyChar(). For KeyEvent.KEY_RELEASED it's always an empty string.
      Parameters:
      event - JBR-generated event to inspect.
      Returns:
      A string of characters that this event generated.
      Throws:
      UnsupportedOperationException - Inspecting this property is not supported on the current platform, or the event was not generated by JBR
    • getCurrentKeyboardLayout

      String getCurrentKeyboardLayout()
      Get platform-dependent logical keyboard layout identifier for the currently selected keyboard layout.
      Returns:
      Keyboard layout identifier
      Throws:
      UnsupportedOperationException - This method is not supported on the current platform
    • getEnabledKeyboardLayouts

      List<String> getEnabledKeyboardLayouts()
      Get a list of logical keyboard layout identifiers for keyboard layouts enabled on the system.
      Returns:
      List of keyboard layout identifiers
      Throws:
      UnsupportedOperationException - This method is not supported on the current platform
    • setReportNationalKeyCodes

      void setReportNationalKeyCodes(boolean value)
      Enables or disables reporting national key codes in KeyEvents. When enabled, KeyEvent.getKeyCode() will return the key code, corresponding to the appropriate ASCII-capable/Latin keyboard. When this option is disabled, the default Java behavior is used.

      For example, with this enabled, pressing the key to the right of Tab (the Q key on the US layout) will result in KeyEvent.VK_A being reported. Pressing the same key on a non-Latin layout (like Russian) will result in KeyEvent.VK_Q. This way, the key codes reported through KeyEvent.getKeyCode() would be the most appropriate ones to detect keyboard shortcuts.

      Parameters:
      value - `true` if this mode needs to be enabled, `false` otherwise
      Throws:
      UnsupportedOperationException - This method is not supported on the current platform
    • setConvertDeadKeyCodesToNormal

      void setConvertDeadKeyCodesToNormal(boolean value)
      Enables or disables reporting dead key codes as normal in KeyEvents. When enabled, KeyEvent.getKeyCode() and KeyEvent.getExtendedKeyCode() will no longer report dead key codes, such as KeyEvent.VK_DEAD_GRAVE. Instead, they will report corresponding "normal" key codes, such as KeyEvent.VK_BACK_QUOTE. When this option is disabled, the default Java behavior is used.
      Parameters:
      value - `true` if this mode needs to be enabled, `false` otherwise
      Throws:
      UnsupportedOperationException - This method is not supported on the current platform