java - Using JavaFX 8 Scene, Read Keyboard Input while running -


i have javafx 8 scene going nicely. now, while else happening, continuously check keyevent/keycode while program running. have timeline called timeline set indefinite , i've set cycle count indefinite

timeline.setcyclecount(timeline.indefinite); 

i'm looking easy method clean , won't make program choppy.

you can use keyevent listener listen when key pressed, release, typed or any of them. matter whether have infinite loop running on thread, if user presses button, listener called.

you need add listener scene , key event want listen to.

scene.addeventhandler(keyevent.key_pressed, (key) -> {       if(key.getcode()==keycode.enter) {           system.out.println("you pressed enter");       } }); 

Comments

Popular posts from this blog

node.js - How to mock a third-party api calls in the backend -

node.js - Why do I get "SOCKS connection failed. Connection not allowed by ruleset" for some .onion sites? -

matlab - 0-by-1 sym - What do I need to change in order to get proper symbolic results? -