B4J Question Mouse Press and Release in Java 11

Discussion in 'B4J Questions' started by petr4ppc, May 31, 2019.

  1. petr4ppc

    petr4ppc Active Member Licensed User

    Dear friends, please

    where I am doing mistake?

    Code:
    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:
    I am using:
    https://openjfx.io/javadoc/11/javafx.graphics/javafx/scene/robot/Robot.html

    Best regards
    p4ppc
     
  2. agraham

    agraham Expert Licensed User

    Just a wild guess but have you tried a Sleep(0) between press and release? It might be that it is only seeing the release as you are not returning to the main thread to process the press command. But there again it might not !
     
  3. stevel05

    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:

    Code:
    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: May 31, 2019
    petr4ppc, agraham and inakigarm like this.
  4. petr4ppc

    petr4ppc Active Member Licensed User

    Agraham, I am trying this:
    Code:
    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:
    Where I am doing mistake, please?
    Best regards
    p4ppc
     
  5. petr4ppc

    petr4ppc Active Member Licensed User

    STEVEl05
    THANK YOU VERY MUCH
    100% it is OK
    Best regards
    p4ppc
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice