JavaFX Android port Listen for volume button presses -
i'm trying develop android app javafx. there way listen volume button presses on phone can launch code whenever press volume buttons?
you can listen various key codes, e.g.
keycode.escape
== back-buttonkeycode.volume_up
/keycode.volume_down
keycode.home
- i'm not sure, haven't tested itkeycode.context_menu
- i'm not sure, haven't tested it
in application-extending main class this:
@override public void start(stage stage) throws exception { // init scene , ui scene.addeventfilter(keyevent.any, this::handleglobalkeyevents); // whatever want } private void handleglobalkeyevents(keyevent event) { // use more specific key event type // --> keyevent.key_released == event.geteventtype() // --> keyevent.key_pressed == event.geteventtype() // without it, react on both events, doing 1 operation if (event.getcode().equals(keycode.escape) && keyevent.key_released == event.geteventtype()) { if (backhandler != null) backhandler.back(); event.consume(); } }
regards, daniel
Comments
Post a Comment