B4J Question SendKey error

micro

Well-Known Member
Licensed User
Longtime User
Hi to all
this is the link for reference constant value
http://docs.oracle.com/javase/7/docs/api/constant-values.html#java.awt.event.KeyEvent.VK_COLON
In my program i use SendKey(513) for send ":"
(robot is JavaObject)
B4X:
Sub SendKey(code As Int)
    If shift Or maiuscolo Then robot.RunMethod("keyPress", Array As Object(16))
    robot.RunMethod("keyPress", Array As Object(code))
     Sleep(100)
    robot.RunMethod("keyRelease", Array As Object(code))
    If shift Or maiuscolo Then robot.RunMethod("keyRelease", Array As Object(16))
    If shift Then
        shift = False
        LoadMinuscolo
    End If
End Sub
but not work (null char).
Why?

Thanks
 

Roycefer

Well-Known Member
Licensed User
Longtime User
Most computers don't have a colon key. Instead, they have a semi-colon key and you have to press shift and then the semi-colon key to get a text editor to recognize that the user intends for a colon character to be entered. I think you should check out this library: http://b4x.com/android/forum/threads/jawtrobot-invoke-keyboard-and-mouse-events-etc.55832/ instead of trying to decipher key-code usage. You might find this library's RobotPaste() method useful. There are also methods for pressing single keys and numerous other utilities.
 
Upvote 0

micro

Well-Known Member
Licensed User
Longtime User
I'm back.
Why with raspberry the method RobotPaste() crash the program?
In windows all ok.
This is the java version on my raspberry 2
java version "1.8.0"
Java(TM) SE Runtime Environment (build 1.8.0-b132)
 
Upvote 0

Roycefer

Well-Known Member
Licensed User
Longtime User
Are you getting a stack trace from the crash? Can you post it here? RobotPaste() was recently re-written to be cross-platform and other users reported it working quite well on other platforms.
 
Upvote 0

Roycefer

Well-Known Member
Licensed User
Longtime User
I just tested the RobotPaste() method on the RasPi 2 with Raspbian via NOOBS with jdk8 installed. It worked as expected. Can you give a little more info about what you were doing and in what conditions? A stack trace would be really helpful.
 
Upvote 0

micro

Well-Known Member
Licensed User
Longtime User
Thanks Roycefer
Crash in debug mode, I have not run in release mode.
When I return I see the errors displayed.

Best Regards
 
Upvote 0

micro

Well-Known Member
Licensed User
Longtime User
This is the error log...
B4X:
Error occurred on line: 944 (SoftKey)
java.lang.NullPointerException
    at butt.droid.awtRobot.AWTRobot.RobotPaste(AWTRobot.java:641)
    at b4j.example.softkey._keyimg15_mousepressed(softkey.java:1311)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:483)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:593)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:225)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:158)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:483)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:93)
    at anywheresoftware.b4a.ShellBA.raiseE
vent2(ShellBA.java:90)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:84)
    at anywheresoftware.b4j.objects.NodeWrapper$2.handle(NodeWrapper.java:96)
    at anywheresoftware.b4j.objects.NodeWrapper$2.handle(NodeWrapper.java:1)
    at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86)
    at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
    at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
    at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
    at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
    at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
    at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    at com.sun.javafx.event.BasicE
ventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
    at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
    at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54)
    at javafx.event.Event.fireEvent(Event.java:204)
    at javafx.scene.Scene$MouseHandler.process(Scene.java:3746)
    at javafx.scene.Scene$MouseHandler.access$1800(Scene.java:3471)
    at javafx.scene.Scene.impl_processMouseEvent(Scene.java:1695)
    at javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2486)
    at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:314)
    at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:243)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:345)
    at com.sun.glass.ui.View.handleMouseEvent(Vi
ew.java:526)
    at com.sun.glass.ui.View.notifyMouse(View.java:898)
    at com.sun.glass.ui.lens.LensView._notifyMouse(LensView.java:164)
    at com.sun.glass.ui.lens.LensApplication$LensMouseEvent.dispatch(LensApplication.java:391)
    at com.sun.glass.ui.lens.LensApplication._runLoop(LensApplication.java:860)
    at com.sun.glass.ui.lens.LensApplication.access$1800(LensApplication.java:58)
    at com.sun.glass.ui.lens.LensApplication$4.run(LensApplication.java:917)
    at java.lang.Thread.run(Thread.java:744)

This is the line code..
B4X:
awt.RobotPaste("(")
 
Upvote 0

Roycefer

Well-Known Member
Licensed User
Longtime User
Are you able to use the awt.ClipboardStringSet() method or does that throw an Exception too? What about any of the awt.ClipboardString... methods?
 
Upvote 0

micro

Well-Known Member
Licensed User
Longtime User
same problem (although this method is not functional for a softkey, better awt.RobotPaste())
B4X:
Error occurred on line: 1005 (SoftKey)
java.lang.NullPointerException
    at butt.droid.awtRobot.AWTRobot.ClipboardStringSet(AWTRobot.java:668)
    at b4j.example.softkey._keyimg11_mousepressed(softkey.java:1107)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:483)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:593)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:225)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:158)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:483)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:93)
    at anywheresoftware.b4a.ShellB
A.raiseEvent2(ShellBA.java:90)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:84)
    at anywheresoftware.b4j.objects.NodeWrapper$2.handle(NodeWrapper.java:96)
    at anywheresoftware.b4j.objects.NodeWrapper$2.handle(NodeWrapper.java:1)
    at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86)
    at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
    at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
    at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
    at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
    at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
    at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    at com.sun.javafx.even
t.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
    at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
    at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54)
    at javafx.event.Event.fireEvent(Event.java:204)
    at javafx.scene.Scene$MouseHandler.process(Scene.java:3746)
    at javafx.scene.Scene$MouseHandler.access$1800(Scene.java:3471)
    at javafx.scene.Scene.impl_processMouseEvent(Scene.java:1695)
    at javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2486)
    at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:314)
    at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:243)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:345)
    at com.sun.glass.ui.View.handleMouse
Event(View.java:526)
    at com.sun.glass.ui.View.notifyMouse(View.java:898)
    at com.sun.glass.ui.lens.LensView._notifyMouse(LensView.java:164)
    at com.sun.glass.ui.lens.LensApplication$LensMouseEvent.dispatch(LensApplication.java:391)
    at com.sun.glass.ui.lens.LensApplication._runLoop(LensApplication.java:860)
    at com.sun.glass.ui.lens.LensApplication.access$1800(LensApplication.java:58)
    at com.sun.glass.ui.lens.LensApplication$4.run(LensApplication.java:917)
    at java.lang.Thread.run(Thread.java:744)

this is the line code
B4X:
awt.ClipboardStringSet("à")
 Main.provatxt.text = awt.ClipboardStringGet

I solved with shift + keycode
but it would be nice to run awt.RobotPaste()
 
Upvote 0

Roycefer

Well-Known Member
Licensed User
Longtime User
Are you running your program on the RasPi with superuser permissions? I run my programs on my RasPi 2 without superuser permissions and the entire jAWTRobot library works fine. It may be that your RasPi, for some reason, is restricting access to the system clipboard. By the way, that's where RobotPaste() is failing in your example. It's not able to access to the system clipboard. That's why I asked if you were able to use the Clipboard... methods. I suggest trying the program in release mode and with superuser privileges.
 
Upvote 0

micro

Well-Known Member
Licensed User
Longtime User
Hi to all
tried as superuser but same problem,
Trying the program in release mode but with awt.RobotPaste() crash always

B4X:
pi@raspberrypi ~ $ sudo java -jar /home/pi/Softkey/softkey.jar
Program started.
java.awt.AWTException: headless environment
        at java.awt.Robot.<init>(Robot.java:94)
        at butt.droid.awtRobot.AWTRobot.<init>(AWTRobot.java:81)
        at b4j.example.softkey._class_globals(softkey.java:187)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:483)
        at anywheresoftware.b4a.BA.raiseEvent2(BA.java:93)
        at b4j.example.softkey.innerInitialize(softkey.java:23)
        at b4j.example.softkey._initialize(softkey.java:639)
        at b4j.example.main._appstart(main.java:58)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:483)
        at anywheresoftware.b4a.BA.raiseEvent2(BA.java:93)
        at anywheresoftware.b4a.BA.raiseEvent(BA.java:84)
        at b4j.example.main.start(main.java:36)
        at com.sun.javafx.application.LauncherImpl$8.run(LauncherImpl.java:837)
        at com.sun.javafx.application.PlatformImpl$7.run(PlatformImpl.java:335)
        at com.sun.javafx.application.PlatformImpl$6$1.run(PlatformImpl.java:301)
        at com.sun.javafx.application.PlatformImpl$6$1.run(PlatformImpl.java:298)
        at java.security.AccessController.doPrivileged(Native Method)
        at com.sun.javafx.application.PlatformImpl$6.run(PlatformImpl.java:298)
        at com.sun.glass.ui.lens.LensApplication$RunnableEvent.dispatch(LensApplication.java:182)
        at com.sun.glass.ui.lens.LensApplication._runLoop(LensApplication.java:860)
        at com.sun.glass.ui.lens.LensApplication.access$1800(LensApplication.java:58)
        at com.sun.glass.ui.lens.LensApplication$4.run(LensApplication.java:917)
        at java.lang.Thread.run(Thread.java:744)
softkey._keyimg11_mousepressed (java line: 724)
java.lang.NullPointerException
        at butt.droid.awtRobot.AWTRobot.RobotPaste(AWTRobot.java:641)
        at b4j.example.softkey._keyimg11_mousepressed(softkey.java:724)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:483)
        at anywheresoftware.b4a.BA.raiseEvent2(BA.java:93)
        at anywheresoftware.b4a.BA.raiseEvent(BA.java:84)
        at anywheresoftware.b4j.objects.NodeWrapper$2.handle(NodeWrapper.java:96)
        at anywheresoftware.b4j.objects.NodeWrapper$2.handle(NodeWrapper.java:1)
        at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86)
        at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
        at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
        at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
        at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
        at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
        at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
        at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
        at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
        at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
        at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
        at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54)
        at javafx.event.Event.fireEvent(Event.java:204)
        at javafx.scene.Scene$MouseHandler.process(Scene.java:3746)
        at javafx.scene.Scene$MouseHandler.access$1800(Scene.java:3471)
        at javafx.scene.Scene.impl_processMouseEvent(Scene.java:1695)
        at javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2486)
        at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:314)
        at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:243)
        at java.security.AccessController.doPrivileged(Native Method)
        at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:345)
        at com.sun.glass.ui.View.handleMouseEvent(View.java:526)
        at com.sun.glass.ui.View.notifyMouse(View.java:898)
        at com.sun.glass.ui.lens.LensView._notifyMouse(LensView.java:164)
        at com.sun.glass.ui.lens.LensApplication$LensMouseEvent.dispatch(LensApplication.java:391)
        at com.sun.glass.ui.lens.LensApplication._runLoop(LensApplication.java:860)
        at com.sun.glass.ui.lens.LensApplication.access$1800(LensApplication.java:58)
        at com.sun.glass.ui.lens.LensApplication$4.run(LensApplication.java:917)
        at java.lang.Thread.run(Thread.java:744)

pi@raspberrypi ~ $
 
Upvote 0

Roycefer

Well-Known Member
Licensed User
Longtime User
Now we are getting somewhere: the headless environment Exception means your RasPi doesn't have a screen. java.awt.Robot cannot be used in a headless environment.
 
Upvote 0
Top