KeyCombination

A KeyCombination (AKA keyboard shortcut), is a combination of a Key, and set of zero or more modifier keys (Shift, Control, Alt and Super).

They are commonly used to define shortcuts for actions. For example, the standard Undo KeyCombination is Control + Key.Z.

Use KeyEvent.matches to test if a KeyEvent matches a particular KeyCombination.

There are methods on Key and KeyCombination to create KeyCombinations in a readable manner. e.g. :

val undoShortcut = Key.Z.control()
val redoShortcut = Key.Y.control()
val redoShortcut2 = Key.Z.control().shift()

In most cases the modifiers are boolean, but can also use a third don't care state.

For example, we could define Zoom In to be just key MINUS (with no modifiers). But if you do not care about the state of the Shift modifier, then use Key.maybeShift. Now, Zoom In would match MINUS as well as Shift + MINUS.

I chose this example, because of Zoom Out. There is no PLUS key! (PLUS is Shift + EQUALS).

val zoomOut = Key.MINUS.maybeShift() // Or we could use Key.MINUS.noMods()
val zoomIn = Key.EQUAL.maybeShift()

Pressing the Equals key will match zoomIn, regardless of whether Shift is down or up, but will not match if Control, Super or Alt are pressed.

Constructors

Link copied to clipboard
constructor(key: Key)

Properties

Link copied to clipboard

Note, this does not include info from maybeMods.

Link copied to clipboard
val key: Key
Link copied to clipboard

Which modifier keys could be pressed. The sum of any of : Event.MOD_SHIFT, Event.MOD_CONTROL, Event.MOD_ALT, Event.MOD_SUPER

Link copied to clipboard

Which modifier keys must be pressed. The sum of any of : Event.MOD_SHIFT, Event.MOD_CONTROL, Event.MOD_ALT, Event.MOD_SUPER

Functions

Link copied to clipboard

Creates a new KeyCombination, based on this one, and also requiring Alt to be down.

Link copied to clipboard

Creates a new KeyCombination, based on this one, and also requiring Control to be down.

Link copied to clipboard

Creates a new KeyCombination, based on this one, where Alt may be either down or up.

Link copied to clipboard

Creates a new KeyCombination, based on this one, where Control may be either down or up.

Link copied to clipboard

Creates a new KeyCombination, based on this one, where Shift may be either down or up.

Link copied to clipboard

Creates a new KeyCombination, based on this one, where Super may be either down or up.

Link copied to clipboard

Creates a new KeyCombination, based on this one, and also requiring Shift to be down.

Link copied to clipboard

Creates a new KeyCombination, based on this one, and also requiring Super to be down. Note, this method is not called super to avoid a clash with the super keyword.

Link copied to clipboard
open override fun toString(): String