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:

java.lang.RuntimeException: Method: keyPress not matched.
at anywheresoftware.b4j.object.JavaObject.RunMethod(JavaObject.java:130)
at XX.uz.main._vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv2(main.java:15512)
at XX.uz.main._boarrived(main.java:19708)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:91)
at anywheresoftware.b4a.BA$3.run(BA.java:247)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:428)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:427)
at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:174)
at java.base/java.lang.Thread.run(Thread.java:834)

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:

java.lang.RuntimeException: Method: keyPress not matched.
at anywheresoftware.b4j.object.JavaObject.RunMethod(JavaObject.java:130)
at XX.uz.main._vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv2(main.java:15512)
at XX.uz.main._boarrived(main.java:19708)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:91)
at anywheresoftware.b4a.BA$3.run(BA.java:247)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:428)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:427)
at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:174)
at java.base/java.lang.Thread.run(Thread.java:834)

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:
java.lang.RuntimeException: Method: keyPress not matched.
at anywheresoftware.b4j.object.JavaObject.RunMethod(JavaObject.java:130)
at XX.uz.main._vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv2(main.java:15512)
at XX.uz.main._boarrived(main.java:19708)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:91)
at anywheresoftware.b4a.BA$3.run(BA.java:247)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:428)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:427)
at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:174)
at java.base/java.lang.Thread.run(Thread.java:834)

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
B4X:
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")))
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
1603519442240.png

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
Top