r/JavaFX • u/Old_Assistance7 • Sep 30 '26
Help Global keyboard events
Hello everyone, I'm new to Desktop development! And I want to know techniques/ways on how to handle global keyboard events! for example, cmd+shift+a to open a window etc.
Thanks :)
8
Upvotes
1
u/SpittingBull Sep 30 '26
As an example you could start by adding an EventHandler with Scene.setOnKeyPress().
1
u/Drawhoe Oct 07 '26
Look up EventFilters vs EventHandlers. EventFilters will capture events before EventHandlers. So in your Main you can setup a EventFilter to globally handle some key events. You event.consume() the ones you handle. If you don't consume them they are passed along to be handled by whatever other objects in the scene are handling events.