Class KeyBinding
java.lang.Object
jfx.incubator.scene.control.input.KeyBinding
This immutable class represents a combination of keys which are used in key mappings.
A key combination consists of a main key and a set of modifier keys.
The main key can be specified by its
key code
or key character, the latter must match values returned by KeyEvent.getCharacter().
A modifier key is shift, control, alt, meta or shortcut.
This class also provides a set of convenience methods for refering to keys found on macOS platform.
- Since:
- 24
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classA builder forKeyBindingobjects. -
Method Summary
Modifier and TypeMethodDescriptionstatic KeyBindingCreates a KeyBinding which corresponds to the key press with the specifiedKeyCodeand thealtkey modifier (optionon macOS).static KeyBinding.BuilderCreates aKeyBinding.Builderwith the specified character.static KeyBinding.BuilderCreates aKeyBinding.Builderwith the specifiedKeyCode.static KeyBindingThis utility method creates aKeyBindingwhich corresponds to the key press with the specifiedKeyCodeand the macOS⌘ commandkey modifier.static KeyBindingCreates a KeyBinding which corresponds to the key press with the specifiedKeyCodeand thectrlkey modifier (controlon macOS).static KeyBindingcontrolShift(KeyCode code) Creates a KeyBinding which corresponds to the key press with the specifiedKeyCodeand theshift+ctrlkey modifier (controlon macOS).Returns theKeyCode, or null if the key binding is not for a key code.booleanDetermines whether this key binding if for the key pressed event.booleanDetermines whether this key binding if for the key released event.booleanDetermines whether this key binding if for the key typed event.static KeyBindingCreates aKeyBindingwhich corresponds to the key press with the specifiedKeyCode.static KeyBindingCreates a KeyBinding which corresponds to the key press with the specifiedKeyCodeand theoptionkey modifier on macOS.static KeyBindingCreates a KeyBinding which corresponds to the key press with the specifiedKeyCodeand theshiftkey modifier.static KeyBindingshiftOption(KeyCode code) Creates a KeyBinding which corresponds to the key press with the specifiedKeyCodeand theshift+optionkey modifiers on macOS.static KeyBindingshiftShortcut(KeyCode code) Creates a KeyBinding which corresponds to the key press with the specifiedKeyCodeand theshift+ shortcut key modifier (⌘ commandon macOS,ctrlelsewhere).static KeyBindingCreates a KeyBinding which corresponds to the key press with the specifiedKeyCodeand the shortcut key modifier (⌘ commandon macOS,ctrlelsewhere).withNewKeyCode(KeyCode newCode) Creates a new instance ofKeyBindingwith the newKeyCodeand the same set of the modifiers.
-
Method Details
-
of
Creates aKeyBindingwhich corresponds to the key press with the specifiedKeyCode.- Parameters:
code- the key code- Returns:
- the KeyBinding
-
command
This utility method creates aKeyBindingwhich corresponds to the key press with the specifiedKeyCodeand the macOS⌘ commandkey modifier.This method returns
nullon non-macOS platforms.- Parameters:
code- the key code- Returns:
- the KeyBinding, or null
-
alt
Creates a KeyBinding which corresponds to the key press with the specifiedKeyCodeand thealtkey modifier (optionon macOS).This method is equivalent to
option(KeyCode)on macOS.- Parameters:
code- the key code- Returns:
- the KeyBinding
-
control
Creates a KeyBinding which corresponds to the key press with the specifiedKeyCodeand thectrlkey modifier (controlon macOS).- Parameters:
code- the key code- Returns:
- the KeyBinding
-
controlShift
Creates a KeyBinding which corresponds to the key press with the specifiedKeyCodeand theshift+ctrlkey modifier (controlon macOS).- Parameters:
code- the key code- Returns:
- the KeyBinding
-
option
Creates a KeyBinding which corresponds to the key press with the specifiedKeyCodeand theoptionkey modifier on macOS.This method returns
nullon non-macOS platforms. On macOS, it is equivalent to callingalt(KeyCode).- Parameters:
code- the key code- Returns:
- the KeyBinding, or null
-
shift
Creates a KeyBinding which corresponds to the key press with the specifiedKeyCodeand theshiftkey modifier.- Parameters:
code- the key code- Returns:
- the KeyBinding
-
shortcut
Creates a KeyBinding which corresponds to the key press with the specifiedKeyCodeand the shortcut key modifier (⌘ commandon macOS,ctrlelsewhere).- Parameters:
code- the key code- Returns:
- the KeyBinding
-
shiftOption
Creates a KeyBinding which corresponds to the key press with the specifiedKeyCodeand theshift+optionkey modifiers on macOS.This method returns
nullon non-macOS platforms.- Parameters:
code- the key code- Returns:
- the KeyBinding, or null
-
shiftShortcut
Creates a KeyBinding which corresponds to the key press with the specifiedKeyCodeand theshift+ shortcut key modifier (⌘ commandon macOS,ctrlelsewhere).- Parameters:
code- the key code- Returns:
- the KeyBinding, or null
-
withNewKeyCode
Creates a new instance ofKeyBindingwith the newKeyCodeand the same set of the modifiers.- Parameters:
newCode- the key code- Returns:
- the KeyBinding
-
isKeyPressed
public boolean isKeyPressed()Determines whether this key binding if for the key pressed event.- Returns:
- true if this key binding if for the key press event
-
isKeyReleased
public boolean isKeyReleased()Determines whether this key binding if for the key released event.- Returns:
- true if this key binding if for the key release event
-
isKeyTyped
public boolean isKeyTyped()Determines whether this key binding if for the key typed event.- Returns:
- true if this key binding if for the key typed event
-
getKeyCode
-
builder
Creates aKeyBinding.Builderwith the specifiedKeyCode.- Parameters:
code- the key code- Returns:
- the Builder instance
-
builder
Creates aKeyBinding.Builderwith the specified character. The string must correspond to the value returned byKeyEvent.getCharacter().- Parameters:
character- the character- Returns:
- the Builder instance
-