HI, All
One my B4J app uses key listener as many times shown on the forum.
But now i have copy-pasted the code to another app - and it does not work fully - no event.
The same code as usual:
Tried and r.AddEventFilter with correct event sub name updating - also no help.
Libs JavaObject and Reflection are included OK, no any errors.
App uses also MenuBar and EventFilter for mouse events (later in the class), but if to remove them for test - no help anyway.
But no "_Event" triggered.
What trick may be forgotten from 1st app where works OK ?
One my B4J app uses key listener as many times shown on the forum.
But now i have copy-pasted the code to another app - and it does not work fully - no event.
The same code as usual:
B4X:
AddKeyPressedListener(MainForm)
...
Sub AddKeyPressedListener(myf As Form)
Dim r As Reflector
r.Target = myf.RootPane
r.AddEventHandler("Main_KeyPressed", "javafx.scene.input.KeyEvent.KEY_PRESSED")
r.AddEventHandler("Main_KeyPressed", "javafx.scene.input.KeyEvent.KEY_RELEASED")
End Sub
Private Sub Main_KeyPressed_Event(e As Event)
Dim KE As Reflector
KE.Target = e 'e is a KeyEvent instance
' Dim KeyChar As String = KE.RunMethod("getCharacter")
Dim KeyCode As String = KE.RunMethod("getCode")
' Dim KeyText As String = KE.RunMethod("getText")
Dim EventType As String = KE.RunMethod("getEventType")
' Log(EventType)
Select EventType
Case "KEY_PRESSED"
Select KeyCode
Case "ESCAPE"
Log("ESC")
'next my code
Case "CONTROL"
KEY_CTRL_PRESSED = True
Case "X"
If KEY_CTRL_PRESSED Then
Log("CTRL+X PRESSED")
End If
End Select
Case "KEY_RELEASED"
If KeyCode = "CONTROL" Then
KEY_CTRL_PRESSED = False
End If
End Select
e.Consume
End Sub
Tried and r.AddEventFilter with correct event sub name updating - also no help.
Libs JavaObject and Reflection are included OK, no any errors.
App uses also MenuBar and EventFilter for mouse events (later in the class), but if to remove them for test - no help anyway.
But no "_Event" triggered.
What trick may be forgotten from 1st app where works OK ?
Last edited: