B4J Question use keyboard ??

ilan

Expert
Licensed User
Longtime User
hi

how can i use keyboard to do some actions in my b4j app (UI app)?

i tried jreflection lib but it seems not to work (or maybe i do something wrong)
i just dont get anything in the logs when i press any button.

can someone help me please
 

Daestrum

Expert
Licensed User
Longtime User
An example just using jReflection
B4X:
Sub AppStart (Form1 As Form, Args() As String)
    MainForm = Form1
    Dim Obj As Reflector
    Obj.Target = MainForm.RootPane
    Obj.AddEventHandler2("RootPaneKeyEvent", "onKeyPressedProperty")
    MainForm.Show
    MainForm.RootPane.RequestFocus
End Sub

Sub RootPaneKeyEvent_Event(e As Event)
    ' bit hackish to get the code
    Dim theKey As String = e
    'Log(e)
    Log("key pressed "& theKey.SubString2(theKey.IndexOf(", code = ")+9,theKey.Length-1))
End Sub
 
Upvote 0

ilan

Expert
Licensed User
Longtime User
thanx to all, i just had to requestfocus to the rootpanel of mainform

gameview would be the right choice since i want to make a game but because it is for the game competition where no game libs are allowed i will use jreflection

thanx guys!
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…