Class KeyCodeCombination
java.lang.Object
javafx.scene.input.KeyCombination
javafx.scene.input.KeyCodeCombination
This class represents a key combination in which the main key is specified
by its
KeyCode. This is the recommended way to specify a shortcut
that does not involve a symbol or punctuation (for such a shortcut a
KeyCharacterCombination is preferred).- Since:
- JavaFX 2.0
-
Nested Class Summary
Nested classes/interfaces declared in class KeyCombination
KeyCombination.Modifier, KeyCombination.ModifierValueModifier and TypeClassDescriptionstatic final classThis class represents a pair of modifier key and its value.static enumModifierValuespecifies state of modifier keys. -
Field Summary
Fields declared in class KeyCombination
ALT_ANY, ALT_DOWN, CONTROL_ANY, CONTROL_DOWN, META_ANY, META_DOWN, NO_MATCH, SHIFT_ANY, SHIFT_DOWN, SHORTCUT_ANY, SHORTCUT_DOWNModifier and TypeFieldDescriptionstatic final KeyCombination.ModifierModifier which specifies that thealtkey can be either up or down.static final KeyCombination.ModifierModifier which specifies that thealtkey must be down.static final KeyCombination.ModifierModifier which specifies that thecontrolkey can be either up or down.static final KeyCombination.ModifierModifier which specifies that thecontrolkey must be down.static final KeyCombination.ModifierModifier which specifies that themetakey can be either up or down.static final KeyCombination.ModifierModifier which specifies that themetakey must be down.static final KeyCombinationA KeyCombination that will match with no events.static final KeyCombination.ModifierModifier which specifies that theshiftkey can be either up or down.static final KeyCombination.ModifierModifier which specifies that theshiftkey must be down.static final KeyCombination.ModifierModifier which specifies that theshortcutkey can be either up or down.static final KeyCombination.ModifierModifier which specifies that theshortcutkey must be down. -
Constructor Summary
ConstructorsConstructorDescriptionKeyCodeCombination(KeyCode code, KeyCombination.Modifier... modifiers) Constructs aKeyCodeCombinationfor the specified main key and with the specified list of modifiers.KeyCodeCombination(KeyCode code, KeyCombination.ModifierValue shift, KeyCombination.ModifierValue control, KeyCombination.ModifierValue alt, KeyCombination.ModifierValue meta, KeyCombination.ModifierValue shortcut) Constructs aKeyCodeCombinationfor the specified main key and with an explicit specification of all modifier keys. -
Method Summary
Modifier and TypeMethodDescriptionbooleanTests whether thisKeyCodeCombinationequals to the specified object.final KeyCodegetCode()Gets the key code associated with this key combination.getName()Returns a string representation of thisKeyCodeCombination.inthashCode()Returns a hash code value for thisKeyCodeCombination.booleanTests whether this key combination matches the key combination in the givenKeyEvent.Methods declared in class KeyCombination
getAlt, getControl, getDisplayText, getMeta, getShift, getShortcut, keyCombination, toString, valueOfModifier and TypeMethodDescriptiongetAlt()The state of thealtkey in this key combination.The state of thecontrolkey in this key combination.Returns a string representation of thisKeyCombinationthat is suitable for display in a user interface (for example, beside a menu item).getMeta()The state of themetakey in this key combination.getShift()The state of theshiftkey in this key combination.The state of theshortcutkey in this key combination.static KeyCombinationkeyCombination(String name) Constructs a newKeyCombinationfrom the specified string.toString()Returns a string representation of this object.static KeyCombinationConstructs a newKeyCombinationfrom the specified string.
-
Constructor Details
-
KeyCodeCombination
public KeyCodeCombination(KeyCode code, KeyCombination.ModifierValue shift, KeyCombination.ModifierValue control, KeyCombination.ModifierValue alt, KeyCombination.ModifierValue meta, KeyCombination.ModifierValue shortcut) Constructs aKeyCodeCombinationfor the specified main key and with an explicit specification of all modifier keys. Each modifier key can be set toPRESSED,RELEASEDorIGNORED.- Parameters:
code- the key code of the main keyshift- the value of theshiftmodifier keycontrol- the value of thecontrolmodifier keyalt- the value of thealtmodifier keymeta- the value of themetamodifier keyshortcut- the value of theshortcutmodifier key
-
KeyCodeCombination
Constructs aKeyCodeCombinationfor the specified main key and with the specified list of modifiers. All modifier keys which are not explicitly listed are set to the defaultRELEASEDvalue.All possible modifiers which change the default modifier value are defined as constants in the
KeyCombinationclass.- Parameters:
code- the key code of the main keymodifiers- the list of modifier keys and their corresponding values
-
-
Method Details
-
getCode
Gets the key code associated with this key combination.- Returns:
- The key code associated with this key combination
-
match
Tests whether this key combination matches the key combination in the givenKeyEvent. It uses only the key code and the state of the modifier keys from theKeyEventin the test. This means that the method can returntrueonly forKEY_PRESSEDandKEY_RELEASEDevents, but not forKEY_TYPEDevents, which don't have valid key codes.- Overrides:
matchin classKeyCombination- Parameters:
event- the key event- Returns:
trueif the key combinations match,falseotherwise
-
getName
Returns a string representation of thisKeyCodeCombination.The string representation consists of sections separated by plus characters. Each section specifies either a modifier key or the main key.
A modifier key section contains the
KeyCodename of a modifier key. It can be prefixed with theIgnoredkeyword. A non-prefixed modifier key implies itsPRESSEDvalue while the prefixed version implies theIGNOREDvalue. If some modifier key is not specified in the string at all, it means it has the defaultRELEASEDvalue.The main key section contains the key code name of the main key and is the last section in the returned string.
- Overrides:
getNamein classKeyCombination- Returns:
- the string representation of this
KeyCodeCombination
-
equals
Tests whether thisKeyCodeCombinationequals to the specified object.- Overrides:
equalsin classKeyCombination- Parameters:
obj- the object to compare to- Returns:
trueif the objects are equal,falseotherwise
-
hashCode
public int hashCode()Returns a hash code value for thisKeyCodeCombination.- Overrides:
hashCodein classKeyCombination- Returns:
- the hash code value
-