As a platform designed to build rich user interface applications, JavaFX provides many ways for users to interact with your applications. In order to implement user interactions in your applications, at a minimum, you will have to capture key presses on the keyboard and gestures from pointing devices. This recipe shows you how to capture keyboard and mouse events.
When a key from the keyboard is pressed or a mouse event occurs, the JavaFX application framework will generate input events information stored in instances of KeyEvent
and MouseEvent
respectively. These classes are found in the package javafx.scene.input
.
Input events are sent to nodes attached to your scene graph. Therefore, in order to receive input events, you must have at least one node added to your scene. Review the recipe Building a JavaFX application for background information on how to do that.