I\'m finally switching over fully to JavaFX.
I\'m very keen on keystroke functionality.
Is there an equivalent hotkey architecture to the (very good) one yo
In JavaFX you can register a callback for KeyPressed
events.
For example:
myTextField.setOnKeyPressed(event->{
if (event.getCode() == KeyCode.ENTER){
//do something here
}
}
If you wanted to register a global Key combination (say, the typical Ctrl-S for saving) you could instead use:
myScene.getAccellerators().put(
new KeyCodeCombination(KeyCode.S, KeyCombination.CONTROL_DOWN),
() -> { /** save my work **/ }
)
List of available KeyCodeCombinations: https://docs.oracle.com/javafx/2/api/javafx/scene/input/KeyCodeCombination.html
EDIT(1): how event propagation works
From http://docs.oracle.com/javafx/2/events/processing.htm
The event delivery process contains the following steps:
Aha.
This question, from a year ago, already relating to Java 9, reveals what looks like future existence in JavaFX of com.sun.javafx.scene.control.inputmap.InputMap
... obviously at the moment
package com.sun.javafx.scene.control.inputmap
does not exist (in Java 8) (unless I'm very much mistaken).
The person who posed that question, Kleopatra, is something of an expert in Java Swing, and presumably now in JavaFX. We see some early releases of Java 9 happening around now, March 2017, precisely... but having tried googling for the API Javadoc for JavaFX 9, I can't as yet see any sign of com.sun.javafx.scene.control.inputmap.InputMap
.