# Class KeyBinding

java.lang.Object
jfx.incubator.scene.control.input.KeyBinding

public class KeyBinding extends Object
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 Classes
  Modifier and Type
  Class
  Description
  `static class`
  `KeyBinding.Builder`
  A builder for `KeyBinding` objects.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `static KeyBinding`
  `alt(KeyCode code)`
  Creates a KeyBinding which corresponds to the key press with the specified `KeyCode` and the `alt` key modifier (`option` on macOS).
  `static KeyBinding.Builder`
  `builder(String character)`
  Creates a `KeyBinding.Builder` with the specified character.
  `static KeyBinding.Builder`
  `builder(KeyCode code)`
  Creates a `KeyBinding.Builder` with the specified `KeyCode`.
  `static KeyBinding`
  `command(KeyCode code)`
  This utility method creates a `KeyBinding` which corresponds to the key press with the specified `KeyCode` and the macOS `⌘ command` key modifier.
  `static KeyBinding`
  `control(KeyCode code)`
  Creates a KeyBinding which corresponds to the key press with the specified `KeyCode` and the `ctrl` key modifier (`control` on macOS).
  `static KeyBinding`
  `controlShift(KeyCode code)`
  Creates a KeyBinding which corresponds to the key press with the specified `KeyCode` and the `shift` + `ctrl` key modifier (`control` on macOS).
  `KeyCode`
  `getKeyCode()`
  Returns the `KeyCode`, or null if the key binding is not for a key code.
  `boolean`
  `isKeyPressed()`
  Determines whether this key binding if for the key pressed event.
  `boolean`
  `isKeyReleased()`
  Determines whether this key binding if for the key released event.
  `boolean`
  `isKeyTyped()`
  Determines whether this key binding if for the key typed event.
  `static KeyBinding`
  `of(KeyCode code)`
  Creates a `KeyBinding` which corresponds to the key press with the specified `KeyCode`.
  `static KeyBinding`
  `option(KeyCode code)`
  Creates a KeyBinding which corresponds to the key press with the specified `KeyCode` and the `option` key modifier on macOS.
  `static KeyBinding`
  `shift(KeyCode code)`
  Creates a KeyBinding which corresponds to the key press with the specified `KeyCode` and the `shift` key modifier.
  `static KeyBinding`
  `shiftOption(KeyCode code)`
  Creates a KeyBinding which corresponds to the key press with the specified `KeyCode` and the `shift` + `option` key modifiers on macOS.
  `static KeyBinding`
  `shiftShortcut(KeyCode code)`
  Creates a KeyBinding which corresponds to the key press with the specified `KeyCode` and the `shift` + shortcut key modifier (`⌘ command` on macOS, `ctrl` elsewhere).
  `static KeyBinding`
  `shortcut(KeyCode code)`
  Creates a KeyBinding which corresponds to the key press with the specified `KeyCode` and the shortcut key modifier (`⌘ command` on macOS, `ctrl` elsewhere).
  `KeyBinding`
  `withNewKeyCode(KeyCode newCode)`
  Creates a new instance of `KeyBinding` with the new `KeyCode` and the same set of the modifiers.

  ### Methods declared in class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Method Details

  - ### of

    public static KeyBinding of(KeyCode code)
    Creates a `KeyBinding` which corresponds to the key press with the specified `KeyCode`.
    Parameters:
      `code` - the key code
    Returns:
      the KeyBinding

  - ### command

    public static KeyBinding command(KeyCode code)
    This utility method creates a `KeyBinding` which corresponds to the key press with the specified `KeyCode` 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

    public static KeyBinding alt(KeyCode code)
    Creates a KeyBinding which corresponds to the key press with the specified `KeyCode` and the `alt` key modifier (`option` on macOS).

    This method is equivalent to `option(KeyCode)` on macOS.

    Parameters:
      `code` - the key code
    Returns:
      the KeyBinding

  - ### control

    public static KeyBinding control(KeyCode code)
    Creates a KeyBinding which corresponds to the key press with the specified `KeyCode` and the `ctrl` key modifier (`control` on macOS).
    Parameters:
      `code` - the key code
    Returns:
      the KeyBinding

  - ### controlShift

    public static KeyBinding controlShift(KeyCode code)
    Creates a KeyBinding which corresponds to the key press with the specified `KeyCode` and the `shift` + `ctrl` key modifier (`control` on macOS).
    Parameters:
      `code` - the key code
    Returns:
      the KeyBinding

  - ### option

    public static KeyBinding option(KeyCode code)
    Creates a KeyBinding which corresponds to the key press with the specified `KeyCode` and the `option` key modifier on macOS.

    This method returns `null` on non-macOS platforms. On macOS, it is equivalent to calling `alt(KeyCode)`.

    Parameters:
      `code` - the key code
    Returns:
      the KeyBinding, or null

  - ### shift

    public static KeyBinding shift(KeyCode code)
    Creates a KeyBinding which corresponds to the key press with the specified `KeyCode` and the `shift` key modifier.
    Parameters:
      `code` - the key code
    Returns:
      the KeyBinding

  - ### shortcut

    public static KeyBinding shortcut(KeyCode code)
    Creates a KeyBinding which corresponds to the key press with the specified `KeyCode` and the shortcut key modifier (`⌘ command` on macOS, `ctrl` elsewhere).
    Parameters:
      `code` - the key code
    Returns:
      the KeyBinding

  - ### shiftOption

    public static KeyBinding shiftOption(KeyCode code)
    Creates a KeyBinding which corresponds to the key press with the specified `KeyCode` and the `shift` + `option` key modifiers on macOS.

    This method returns `null` on non-macOS platforms.

    Parameters:
      `code` - the key code
    Returns:
      the KeyBinding, or null

  - ### shiftShortcut

    public static KeyBinding shiftShortcut(KeyCode code)
    Creates a KeyBinding which corresponds to the key press with the specified `KeyCode` and the `shift` + shortcut key modifier (`⌘ command` on macOS, `ctrl` elsewhere).
    Parameters:
      `code` - the key code
    Returns:
      the KeyBinding, or null

  - ### withNewKeyCode

    public KeyBinding withNewKeyCode(KeyCode newCode)
    Creates a new instance of `KeyBinding` with the new `KeyCode` 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

    public KeyCode getKeyCode()
    Returns the `KeyCode`, or null if the key binding is not for a key code.
    Returns:
      key code, or null

  - ### builder

    public static KeyBinding.Builder builder(KeyCode code)
    Creates a `KeyBinding.Builder` with the specified `KeyCode`.
    Parameters:
      `code` - the key code
    Returns:
      the Builder instance

  - ### builder

    public static KeyBinding.Builder builder(String character)
    Creates a `KeyBinding.Builder` with the specified character. The string must correspond to the value returned by `KeyEvent.getCharacter()`.
    Parameters:
      `character` - the character
    Returns:
      the Builder instance