B4J Question Mouse Press and Release in Java 11

petr4ppc

Active Member
Licensed User
Dear friends, please

where I am doing mistake?

B4X:
        Dim robot As JavaObject
        robot.InitializeNewInstance("javafx.scene.robot.Robot", Null)
        Dim MouseButton As JavaObject
        MouseButton.InitializeStatic("javafx.scene.input.MouseButton")
        robot.RunMethod("mousePress", Array(MouseButton.GetField("PRIMARY"))) 'left button
        robot.RunMethod("mouseRelease", Array(MouseButton.GetField("PRIMARY"))) 'left button
I get:
java.lang.RuntimeException: Method: mousePress not matched.
I am using:
https://openjfx.io/javadoc/11/javafx.graphics/javafx/scene/robot/Robot.html

Best regards
p4ppc
 

stevel05

Expert
Licensed User
The MousePress and Mouserelease methods require a vararg argument which can be an array, but it has to be of the correct type:

B4X:
    Dim robot As JavaObject
    robot.InitializeNewInstance("javafx.scene.robot.Robot", Null)
    Dim MouseButton As JavaObject
    MouseButton.InitializeStatic("javafx.scene.input.MouseButton")
    Dim MBA As Object = MouseButton.InitializeArray("javafx.scene.input.MouseButton",Array(MouseButton.GetField("PRIMARY")))
    robot.RunMethod("mousePress", Array(MBA)) 'left button
    robot.RunMethod("mouseRelease", Array(MBA)) 'left button
 
Last edited:

petr4ppc

Active Member
Licensed User
Agraham, I am trying this:
B4X:
         Dim robot As JavaObject
                    robot.InitializeNewInstance("javafx.scene.robot.Robot", Null)
                    Dim MouseButton As JavaObject
                    MouseButton.InitializeStatic("javafx.scene.input.MouseButton")
                    robot.RunMethod("mousePress", Array(MouseButton.GetField("PRIMARY"))) 'left button
                    Sleep(50)
                    robot.RunMethod("mouseRelease", Array(MouseButton.GetField("PRIMARY"))) 'left button
and I get same result in logs:
java.lang.RuntimeException: Method: mousePress not matched.
at anywheresoftware.b4j.object.JavaObject.RunMethod(JavaObject.java:130)
at anywheresoftware.b4j.object.JavaObject.RunMethod(JavaObject.java:130)
Where I am doing mistake, please?
Best regards
p4ppc
 
Top