Class KeyBind

java.lang.Object
megalodonte.base.v2.KeyBind

public final class KeyBind extends Object
Keyboard shortcut binding utility. Registers key combinations (with optional modifiers) and attaches them to a Scene or Node.

Usage:

new KeyBind()
    .on(KeyCode.DIGIT1, () -> showPopup("Shortcut SHIFT+1!"), KeyBind.Modifier.SHIFT)
    .on(KeyCode.S,      () -> save(),                        KeyBind.Modifier.CTRL)
    .on(KeyCode.F5,     () -> reload())
    .attach(scene);
  • Constructor Details

    • KeyBind

      public KeyBind()
  • Method Details

    • on

      public KeyBind on(javafx.scene.input.KeyCode key, Runnable action, KeyBind.Modifier... modifiers)
      Registers a key combination with an action.
      Parameters:
      key - the key code
      action - the action to run when the combo is pressed
      modifiers - optional modifiers (SHIFT, CTRL, ALT)
      Returns:
      this instance for chaining
    • attach

      public void attach(ScreenContextInterface screenContext)
      Attaches the key bindings to a screen context's key event filter.