Win a copy of Serverless Applications with Node.js this week in the NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Stephan van Hulst
  • Ron McLeod
  • Tim Moores
  • salvin francis
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Vijitha Kumara

javafx globally listen keyboard events  RSS feed

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does anyone know how to globally listen to all keyboard events in a javafx application? No matter which Node is focused or shown.

In Swing it was achieved by this:




Thanks,

Hugo.
 
Sheriff
Posts: 5813
150
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think it can be done by listening to the scene.  I'll check.
 
Knute Snortum
Sheriff
Posts: 5813
150
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nope.  At least it's not as simple as this:
Maybe if you tell me why you want to do this, we could find another solution.  Or maybe someone more knowledgeable can suggest something.
 
Hugo Larson
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Already did what you suggest listening on the entire scene and the stage but it does not work like my example in Swing.
I want for example to capture to F1 in the entire Fx application no matter what Dialog or node is shown.
 
Knute Snortum
Sheriff
Posts: 5813
150
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay, I've got it.  You need to register an event filter, instead of using one of the convenience methods, like this:
 
Hugo Larson
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Try this and click the button.
When the dialog is shown the F1 key does not work.

 
Knute Snortum
Sheriff
Posts: 5813
150
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Unfortunately, Alerts are a type of Dialog, and Dialogs use their own Stage and Scene.  You might be able to create a class that is like Alert but uses the same Stage and Scene, although I'm having a hard time thinking about how that would work.  Maybe create a rectangle with a high "z" setting and fill it in.  
 
Knute Snortum
Sheriff
Posts: 5813
150
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nope, it's not going to work.  Short of rewriting javafx.scene.control.Dialog, I'm not sure what to do.
 
Why should I lose weight? They make bigger overalls. And they sure don't make overalls for tiny ads:
global solutions you can do in your home or backyard
https://coderanch.com/t/708587/global-solutions-home-backyard
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!