B4J Question Non UI Send Key

BarryW

Active Member
Licensed User
Longtime User
hi. my code is working fine for ui app.

B4X:
   Sub Process_Globals
   Private robot As JavaObject
   Dim timer As Timer
End Sub

Sub AppStart (Form1 As Form, Args() As String)
   Form1.Show
   Dim jo As JavaObject
   jo.InitializeStatic("com.sun.glass.ui.Application")
   robot = jo.RunMethodJO("GetApplication",Null).RunMethodJO("createRobot",Null)
   timer.Initialize("timer", 5000)
   timer.Enabled = True
End Sub

Sub timer_Tick
    SendKey(116)
End Sub

Sub Sleep(ms As Long)
   Dim jo As JavaObject
   jo.InitializeStatic("java.lang.Thread").RunMethod("sleep", Array As Object(ms))
End Sub

Sub SendKey(code As Int)
    robot.RunMethod("keyPress", Array As Object(code))
    Sleep(100)
    robot.RunMethod("keyRelease", Array As Object(code))
End Sub

any help to make it work for non ui app? Tnx...
 

Roycefer

Well-Known Member
Licensed User
Longtime User
You won't have access to the com.sun.glass.ui package when running a non-UI app. It is better to use the jAWTRobot library to do this kind of stuff.
 
Upvote 0
Top