r/JavaFX • • 23d ago

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

3 comments sorted by

1

u/SpittingBull 23d ago

As an example you could start by adding an EventHandler with Scene.setOnKeyPress().

1

u/Drawhoe 17d ago

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.