JBR API to inspect additional properties of AWT key events and keyboards.
-
Method Summary
Modifier and TypeMethodDescriptionGet platform-dependent logical keyboard layout identifier for the currently selected keyboard layout.Get a list of logical keyboard layout identifiers for keyboard layouts enabled on the system.getKeyEventCharacters(KeyEvent event) Get the characters that this key event has produced.intgetKeyEventDeadKeyCode(KeyEvent event) Get the dead key code for the event.intgetKeyEventDeadKeyStroke(KeyEvent event) Get the dead keystroke code for the event.intgetKeyEventUSKeyCode(KeyEvent event) Inspect, which physical key was pressed on the keyboard, regardless of the active logical keyboard layout.voidsetConvertDeadKeyCodesToNormal(boolean value) Enables or disables reporting dead key codes as normal inKeyEvents.voidsetReportNationalKeyCodes(boolean value) Enables or disables reporting national key codes inKeyEvents.
-
Method Details
-
getKeyEventUSKeyCode
Inspect, which physical key was pressed on the keyboard, regardless of the active logical keyboard layout. The list of virtual key codes is found inKeyEvent. 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 aKeyEvent.KEY_PRESSEDor aKeyEvent.KEY_RELEASEDevent- 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 JBRIllegalArgumentException- Passed KeyEvent is not of a valid type
-
getKeyEventDeadKeyCode
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 returnKeyEvent.VK_UNDEFINED. The dead key code will either be aVK_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 aKeyEvent.KEY_PRESSEDor aKeyEvent.KEY_RELEASEDevent- Returns:
- The dead key code if the key is dead,
or
KeyEvent.VK_UNDEFINEDotherwise - Throws:
UnsupportedOperationException- Inspecting this property is not supported on the current platform, or the event was not generated by JBRIllegalArgumentException- Passed KeyEvent is not of a valid type
-
getKeyEventDeadKeyStroke
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 returnKeyEvent.VK_UNDEFINED. The dead key code will either be aVK_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 aKeyEvent.KEY_PRESSEDor aKeyEvent.KEY_RELEASEDevent- Returns:
- The dead keystroke code if the key is dead,
or
KeyEvent.VK_UNDEFINEDotherwise - Throws:
UnsupportedOperationException- Inspecting this property is not supported on the current platform, or the event was not generated by JBRIllegalArgumentException- Passed KeyEvent is not of a valid type
-
getKeyEventCharacters
Get the characters that this key event has produced. ForKeyEvent.KEY_TYPEDit's equivalent toKeyEvent.getKeyChar(). ForKeyEvent.KEY_RELEASEDit'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
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 inKeyEvents. 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_Abeing reported. Pressing the same key on a non-Latin layout (like Russian) will result inKeyEvent.VK_Q. This way, the key codes reported throughKeyEvent.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 inKeyEvents. When enabled,KeyEvent.getKeyCode()andKeyEvent.getExtendedKeyCode()will no longer report dead key codes, such asKeyEvent.VK_DEAD_GRAVE. Instead, they will report corresponding "normal" key codes, such asKeyEvent.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
-