B4J Question Function keys

Didier9

Well-Known Member
Licensed User
Longtime User
I am trying to catch function key pressed events.
This would not be related to which particular widget on the screen has focus, anything within the app would do.
I saw a reference to this post:
but it is not helpful to me. I cannot figure what what this code is doing :(
Is there another example of function key events that I missed?
 

Jorge M A

Well-Known Member
Licensed User
Longtime User
B4J:
Sub AppStart (Form1 As Form, Args() As String)
    MainForm = Form1
    sm.Initialize(Form1.RootPane)
    MainForm.Show
    MainForm.Title = "Key Listener"
    
    AddKeyPressedListener
    
End Sub


Sub AddKeyPressedListener
    Dim r As Reflector
    r.Target = MainForm.RootPane
    r.AddEventHandler("keypressed", "javafx.scene.input.KeyEvent.KEY_PRESSED")
End Sub


Sub KeyPressed_Event (e As Event)
    
        Dim jo As JavaObject = e
        Dim keycode As String = jo.RunMethod("getCode", Null)

        Log(keycode)

        If keycode = "ESCAPE" Or keycode = "C" Then
        Else If keycode = "Y" Then

        Else If keycode = "N" Then
            
        End If
    
End Sub

Require jReflection
 
Upvote 0

sorex

Expert
Licensed User
Longtime User
or select the gameviewhelper lib...

B4X:
Sub AppStart (Form1 As Form, Args() As String)
    Dim gvh As GameViewHelper
    gvh.AddKeyListener("gvh",Form1)
End Sub

Sub gvh_KeyReleased (KeyCode As String) As Boolean
    Select KeyCode
        Case "F1":Log("f1 pressed")
        Case "F2":Log("f2 pressed")
    End Select
End Sub
 
Upvote 0

Didier9

Well-Known Member
Licensed User
Longtime User
That was too easy, I will ask a harder question next time...
Thanks alot, both of you!
 
Upvote 0
Top