Reflection should work. I implemented it as following.
Add a handler
B4X:
Dim r As Reflector
r.Target = PaneGame
r.AddEventHandler("Pane_KeyPressed","javafx.scene.input.KeyEvent.KEY_PRESSED")
Consume the event
B4X:
Private Sub Pane_KeyPressed_Event(e As Event)
keyListener(e)
End Sub
keylistener (dunno if ESC is the correct keycode, I use it for the enter key)
B4X:
Sub keyListener(e As Event)
Dim KE As Reflector
KE.Target = e
Dim keycode As String
keycode = KE.RunMethod("getCode")
If keycode = "ESC" Then
...
End If
End Sub
Dim JO As JavaObject = btnEsc
JO.RunMethod("setCancelButton",Array(True)) 'If Esc pressed
JO = btnDef
JO.RunMethod("setDefaultButton",Array(True)) 'If Enter pressed