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

petr4ppc

Active Member
Licensed 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

Active Member
Licensed 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
 

petr4ppc

Active Member
Licensed 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
 

Erel

Administrator
Staff member
Licensed 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
 

petr4ppc

Active Member
Licensed User
Thank you very much dear B4X friends,

Erel - it is 100% perfect, thank you very much and best regards :)
p4ppc
 
Top