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 class
A builder forKeyBinding
objects. -
Method Summary
Modifier and TypeMethodDescriptionstatic KeyBinding
Creates a KeyBinding which corresponds to the key press with the specifiedKeyCode
and thealt
key modifier (option
on macOS).static KeyBinding.Builder
Creates aKeyBinding.Builder
with the specified character.static KeyBinding.Builder
Creates aKeyBinding.Builder
with the specifiedKeyCode
.static KeyBinding
This utility method creates aKeyBinding
which corresponds to the key press with the specifiedKeyCode
and the macOS⌘ command
key modifier.static KeyBinding
Creates a KeyBinding which corresponds to the key press with the specifiedKeyCode
and thectrl
key modifier (control
on macOS).static KeyBinding
controlShift
(KeyCode code) Creates a KeyBinding which corresponds to the key press with the specifiedKeyCode
and theshift
+ctrl
key modifier (control
on macOS).Returns theKeyCode
, or null if the key binding is not for a key code.boolean
Determines whether this key binding if for the key pressed event.boolean
Determines whether this key binding if for the key released event.boolean
Determines whether this key binding if for the key typed event.static KeyBinding
Creates aKeyBinding
which corresponds to the key press with the specifiedKeyCode
.static KeyBinding
Creates a KeyBinding which corresponds to the key press with the specifiedKeyCode
and theoption
key modifier on macOS.static KeyBinding
Creates a KeyBinding which corresponds to the key press with the specifiedKeyCode
and theshift
key modifier.static KeyBinding
shiftOption
(KeyCode code) Creates a KeyBinding which corresponds to the key press with the specifiedKeyCode
and theshift
+option
key modifiers on macOS.static KeyBinding
shiftShortcut
(KeyCode code) Creates a KeyBinding which corresponds to the key press with the specifiedKeyCode
and theshift
+ shortcut key modifier (⌘ command
on macOS,ctrl
elsewhere).static KeyBinding
Creates a KeyBinding which corresponds to the key press with the specifiedKeyCode
and the shortcut key modifier (⌘ command
on macOS,ctrl
elsewhere).withNewKeyCode
(KeyCode newCode) Creates a new instance ofKeyBinding
with the newKeyCode
and the same set of the modifiers.
-
Method Details
-
of
Creates aKeyBinding
which corresponds to the key press with the specifiedKeyCode
.- Parameters:
code
- the key code- Returns:
- the KeyBinding
-
command
This utility method creates aKeyBinding
which corresponds to the key press with the specifiedKeyCode
and the macOS⌘ command
key modifier.This method returns
null
on 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 specifiedKeyCode
and thealt
key modifier (option
on 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 specifiedKeyCode
and thectrl
key modifier (control
on macOS).- Parameters:
code
- the key code- Returns:
- the KeyBinding
-
controlShift
Creates a KeyBinding which corresponds to the key press with the specifiedKeyCode
and theshift
+ctrl
key modifier (control
on macOS).- Parameters:
code
- the key code- Returns:
- the KeyBinding
-
option
Creates a KeyBinding which corresponds to the key press with the specifiedKeyCode
and theoption
key modifier on macOS.This method returns
null
on 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 specifiedKeyCode
and theshift
key modifier.- Parameters:
code
- the key code- Returns:
- the KeyBinding
-
shortcut
Creates a KeyBinding which corresponds to the key press with the specifiedKeyCode
and the shortcut key modifier (⌘ command
on macOS,ctrl
elsewhere).- Parameters:
code
- the key code- Returns:
- the KeyBinding
-
shiftOption
Creates a KeyBinding which corresponds to the key press with the specifiedKeyCode
and theshift
+option
key modifiers on macOS.This method returns
null
on 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 specifiedKeyCode
and theshift
+ shortcut key modifier (⌘ command
on macOS,ctrl
elsewhere).- Parameters:
code
- the key code- Returns:
- the KeyBinding, or null
-
withNewKeyCode
Creates a new instance ofKeyBinding
with the newKeyCode
and 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.Builder
with the specifiedKeyCode
.- Parameters:
code
- the key code- Returns:
- the Builder instance
-
builder
Creates aKeyBinding.Builder
with the specified character. The string must correspond to the value returned byKeyEvent.getCharacter()
.- Parameters:
character
- the character- Returns:
- the Builder instance
-