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 -

java - Could not locate OpenAL library -

Non Unique Username with ASP.Net Identity 2.0 -