B4J Question Move cursor - SOLVED

petr4ppc

Well-Known Member
Licensed User
Longtime User
Dear friends, please,

I am using Java 11 and I have code:

B4X:
Yes in B4J / No function in standalone:
                         robot.InitializeNewInstance("javafx.scene.robot.Robot", Null)
                         robot.RunMethod("mouseMove", Array As Object(x,y))
Yes in B4J / No function in standalone:
                          Private robot As JavaObject
                          Dim jo As JavaObject
                          jo.InitializeStatic("com.sun.glass.ui.Application")
                          robot = jo.RunMethodJO("GetApplication",Null).RunMethodJO("createRobot",Null)
                          Dim x As Double =123
                          Dim y As Double =100
                          robot.RunMethod("mouseMove", Array As Object(x, y))  
Yes in B4J / No function in standalone:
                          x=205
                          y=200
                         Dim robot As JavaObject
                         robot.InitializeNewInstance("javafx.scene.robot.Robot", Null)
                         robot.RunMethod("mouseMove", Array As Object(x, y))

- When I am running app in B4J then everything is functioned
- but when I have stand alone package, then cursor is not moving

Why please? Where I am doing mistake?
Best regards
p4ppc
 
Last edited:
Solution
If it runs in the IDE environment then your program code looks ok. The only difference between the IDE and standalone package is that in the standalone version things go faster because the overhead of the IDE is missing. So it is possible that your next program step is already executing while the previous step is not completed.

To eliminate that, just add a sleep(5000) delay to see if it works. If it works, then lower the sleep instruction. You can also record a log time after each step to see how much time is used in IDE execution. It's just trying to find the solution.

You could also look to the time ticks needed for the different steps with the following code:

Log Time ticks example:
    Dim Ticks As Long = DateTime.now...

MicroDrie

Well-Known Member
Licensed User
Longtime User
You can give time for a screen update to see what happening with the following code:
Screen update:
    sleep(0)    ' you can increase the value if necessary in steps of 1 msec after each Java call.
 
Upvote 0

petr4ppc

Well-Known Member
Licensed User
Longtime User
Yes MicroDrie, I have this. I can not move cursor. Click is functioned, but moving not.
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
Are there any errors? Run from the run_debug.bat file and check the console window.
 
Upvote 0

MicroDrie

Well-Known Member
Licensed User
Longtime User
If it runs in the IDE environment then your program code looks ok. The only difference between the IDE and standalone package is that in the standalone version things go faster because the overhead of the IDE is missing. So it is possible that your next program step is already executing while the previous step is not completed.

To eliminate that, just add a sleep(5000) delay to see if it works. If it works, then lower the sleep instruction. You can also record a log time after each step to see how much time is used in IDE execution. It's just trying to find the solution.

You could also look to the time ticks needed for the different steps with the following code:

Log Time ticks example:
    Dim Ticks As Long = DateTime.now
    robot.InitializeNewInstance("javafx.scene.robot.Robot", Null)

    Log(DateTime.Now  - Ticks)      ' --- display function ticks
    Dim Ticks As Long = DateTime.now

    ' --- What are X and Y here? <=====
    robot.RunMethod("mouseMove", Array As Object(x,y))
    Log(DateTime.Now  - Ticks)

    ' Yes in B4J / No function in standalone:
    Dim jo As JavaObject

    Dim Ticks As Long = DateTime.now
    jo.InitializeStatic("com.sun.glass.ui.Application")
    Log(DateTime.Now  - Ticks)

    Dim Ticks As Long = DateTime.now
    robot = jo.RunMethodJO("GetApplication",Null).RunMethodJO("createRobot",Null)
    Log(DateTime.Now  - Ticks)
    
    Dim x As Double =123
    Dim y As Double =100
    Dim Ticks As Long = DateTime.now
    robot.RunMethod("mouseMove", Array As Object(x, y))
    Log(DateTime.Now  - Ticks)

    . --- Yes in B4J / No function in standalone:
    x=205
    y=200
    Dim robot As JavaObject

    Dim Ticks As Long = DateTime.now
    robot.InitializeNewInstance("javafx.scene.robot.Robot", Null)
    Log(DateTime.Now  - Ticks)

    ' --- What are X and Y here? <=====
    Dim Ticks As Long = DateTime.now
    robot.RunMethod("mouseMove", Array As Object(x, y))
    Log(DateTime.Now  - Ticks)

Delay function:
    ' --- Yes in B4J / No function in standalone:
    robot.InitializeNewInstance("javafx.scene.robot.Robot", Null)
    sleep(5000)        ' delay 5 seconds

    ' --- What are X and Y here? <=====
    robot.RunMethod("mouseMove", Array As Object(x,y))
    sleep(5000)        ' delay 5 seconds

    ' Yes in B4J / No function in standalone:
    Private robot As JavaObject
    Dim jo As JavaObject
    jo.InitializeStatic("com.sun.glass.ui.Application")
    sleep(5000)        ' delay 5 seconds

    robot = jo.RunMethodJO("GetApplication",Null).RunMethodJO("createRobot",Null)
    sleep(5000)        ' delay 5 seconds

    ' --- What are X and Y here? <=====
    Dim x As Double =123
    Dim y As Double =100
    robot.RunMethod("mouseMove", Array As Object(x, y))
    sleep(5000)        ' delay 5 seconds

    . --- Yes in B4J / No function in standalone:
    x=205
    y=200
    Dim robot As JavaObject
    robot.InitializeNewInstance("javafx.scene.robot.Robot", Null)
    sleep(5000)        ' delay 5 seconds

    ' --- What are X and Y here? <=====
    robot.RunMethod("mouseMove", Array As Object(x, y))
    sleep(5000)        ' delay 5 seconds
 
Upvote 0
Solution

petr4ppc

Well-Known Member
Licensed User
Longtime User
stevel05 and MicroDrie,

thank you very much for your time and advices
, you have true. Everything is solved with sleep function and variables declared as Double,

Best regards,
p4ppc
 
Upvote 0
Top