B4J Question CTRL+V with message - Method: keyPress not matched

petr4ppc

Well-Known Member
Licensed User
Longtime User
Dear friends,

please for advice, I am using ctrl + v for paste:
B4X:
    Dim ta As TextArea
    ta.Initialize("ta")
    Dim jo As JavaObject = ta
    jo.RunMethod("paste", Null)
    ta.SelectAll

robot.RunMethod("keyPress", Array As Object(17))  
robot.RunMethod("keyPress", Array As Object(86))
robot.RunMethod("keyRelease", Array As Object(17))
robot.RunMethod("keyRelease", Array As Object(86))

and I got this message:


Please, what can I do with this? It was functioned in older version of Java
 

petr4ppc

Well-Known Member
Licensed User
Longtime User
Thank you very much for answer,

the purpose is, that I want place the string programaticaly with function CTRL+V to cursor position (for example if I have opened notepad)
I have string in clipboard - this is OK,
but I am doing some mistake with:

B4X:
robot.RunMethod("keyPress", Array As Object(17)) 
robot.RunMethod("keyPress", Array As Object(86))
robot.RunMethod("keyRelease", Array As Object(17))
robot.RunMethod("keyRelease", Array As Object(86))

I get:


Best regards
p4ppc
 
Upvote 0

petr4ppc

Well-Known Member
Licensed User
Longtime User
Thank you for your answer Erel,

Robot init:
B4X:
    robot = temp.InitializeStatic("com.sun.glass.ui.Application").RunMethodJO("GetApplication",Null).RunMethodJO("createRobot",Null)

I am using this:
B4X:
#VirtualMachineArgs: --add-opens javafx.graphics/com.sun.glass.ui=ALL-UNNAMED

Now I am using this code (without "object"):
B4X:
    robot.RunMethod("keyPress", Array (17))
    robot.RunMethod("keyPress", Array (86))
    robot.RunMethod("keyRelease", Array (17))
    robot.RunMethod("keyRelease", Array (86))

and I still get:

Best regards,
p4ppc
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Example:
B4X:
Dim robot As JavaObject
robot.InitializeNewInstance("javafx.scene.robot.Robot", Null)
Dim KeyCode As JavaObject
KeyCode.InitializeStatic("javafx.scene.input.KeyCode")
robot.RunMethod("keyPress", Array(KeyCode.GetField("A")))
robot.RunMethod("keyRelease", Array(KeyCode.GetField("A")))

Keycodes: https://openjfx.io/javadoc/11/javafx.graphics/javafx/scene/input/KeyCode.html
 
Upvote 0

petr4ppc

Well-Known Member
Licensed User
Longtime User
Thank you very much dear B4X friends,

Erel - it is 100% perfect, thank you very much and best regards
p4ppc
 
Upvote 0

micro

Well-Known Member
Licensed User
Longtime User
Hi to all
Why this not work?
B4X:
robot.RunMethod("keyPress", Array(KeyCode.GetField("LEFT_PARENTHESIS")))
robot.RunMethod("keyRelease", Array(KeyCode.GetField("LEFT_PARENTHESIS"))
....
and more

instead of constants how can I directly use the value of the key pressed?
Thanks

Edit:
Sorry, I forgot to use the shift key
but the question always remains valid
 
Last edited:
Upvote 0

micro

Well-Known Member
Licensed User
Longtime User

Keyboard Italian Layout
how do i insert @?
B4X:
robot.RunMethod("keyPress", Array(KeyCode.GetField("AT")))
robot.RunMethod("keyRelease", Array(KeyCode.GetField("AT"))
'Not work
....
robot.RunMethod("keyPress", Array(KeyCode.GetField("ALT")))
robot.RunMethod("keyPress", Array(KeyCode.GetField("AT")))
robot.RunMethod("keyRelease", Array(KeyCode.GetField("AT")))
robot.RunMethod("keyRelease", Array(KeyCode.GetField("ALT")))
'Not work
??
Thanks
 
Upvote 0

agraham

Expert
Licensed User
Longtime User
Try
B4X:
robot.RunMethod("keyPress", Array(KeyCode.GetField("ALT_GRAPH")))
robot.RunMethod("keyPress", Array(KeyCode.GetField("AT")))
robot.RunMethod("keyRelease", Array(KeyCode.GetField("AT")))
robot.RunMethod("keyRelease", Array(KeyCode.GetField("ALT_GRAPH")))
I'm pretty sure the modifier is ALT_GRAPH, it is on an English keyboard key with three characters, but the key might not be AT.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…