B4J Question mouseMove - not recognized cursor which is over some objects (apps)

petr4ppc

Well-Known Member
Licensed User
Longtime User
Dear friends, please for advice,

I have
B4X:
Dim robot As JavaObject
robot.InitializeNewInstance("javafx.scene.robot.Robot", Null)
robot.RunMethod("mouseMove", Array As Object(x, y))

everything is perfect, I can set cursor position, but for example if the cursor is over
some application, for example over the sreen keyboard in windows, then the application
can not detect if the mouse is over the "letters" or over some objects...The letters
in windows screen keyboard are the best example ..

if i use standard mouse then windows screen keyboard can detect the position of cursor (the letter is then colored) which is over the letter (key) "a" or "s" etc...

please can I this solve with b4aj?
Can be cursor which is positioned with JavaObject recognized over "the letters"?

Thank you very much
p4ppc
 

Cableguy

Expert
Licensed User
Longtime User
Have you tried the jhook lib?
 
Upvote 0

petr4ppc

Well-Known Member
Licensed User
Longtime User
Cableguy,

I am trying this lib, but I have UI application and I got error:
java.lang.RuntimeException: StartMessageLoop should only be called in non-UI applications.

p4ppc
 
Upvote 0

petr4ppc

Well-Known Member
Licensed User
Longtime User
Dear friends,

I am playing with this LIB, but if cursor si move over screenkeyboard then nothing is happen (the leeters are not backlighted)
Please for advice, what I am doing wrong?

Best regards
p4ppc

B4X:
Sub Process_Globals
   Dim x As Double =0
   Dim y As Double = 500
   Dim NH As NativeHook
   Dim t As Timer
   Dim tmove As Timer
End sub


 Sub AppStart
 
    NH.Initialize("NH", Me)        'Initializes and registers the NativeHook
    NH.startNativeKeyListener    'starts a NativeKeyListener
    NH.startNativeMouseMotionListener 'startNativeKeyListener    'starts a NativeKeyListener
    NH.startNativeMouseInputListener

    NH.enableKillCode   'Allows you to manually unregister by pressing Windows_Escape
    NH.EnableEventConsumption  'Allows you to consume input events
    t.Initialize("t", 60*1000)
    t.Enabled = True            'Timer will unregister the NativeHook in 1 minute
    tmove.Initialize("tmove", 100)
    tmove.Enabled = True            'Timer will unregister the NativeHook in 1 minute
'    StartMessageLoop
End Sub

Sub NH_Unregistered
    Log("NativeHook unregistered")
'    StopMessageLoop    'No more event loops means this program ends here
End Sub

Sub t_Tick
    t.Enabled = False
    NH.unregisterNativeHook
End Sub

Sub NH_NativeKeyPressed(nke As NativeKeyEvent) As Boolean
    If NH.isCharacter(nke.keyCode) Then
        Log(nke.keyText & " Pressed")
        If nke.keyText=="F" Then Return True    'Consumes the event if the user pressed the "F" key
    End If
    Return False
End Sub

Sub nh_NativeMouseWheelMoved(nmwe As NativeMouseWheelEvent) As Boolean
    Log("Scroll Type: " & nmwe.ScrollType)
    Log("Scroll Amount: " & nmwe.ScrollAmount)
    Log("Wheel Rotation: " & nmwe.WheelRotation)
    Return False
End Sub

Sub nh_NativeMouseMoved(mousemove As NativeMouseEvent) As Boolean
    Log("X: " & mousemove.X)
    Log("y: " & mousemove.Y)
    Log("BTN: " & mousemove.MouseButton)
    Return False
End Sub

Sub MainForm_Closed
    NH.endNativeKeyListener    'starts a NativeKeyListener
    NH.endNativeMouseMotionListener 'startNativeKeyListener    'starts a NativeKeyListener
    NH.endNativeMouseInputListener
End Sub

Sub tmove_Tick
   move
End Sub

Sub move
 x=x+1
 y=500
 Dim robot As JavaObject
 robot.InitializeNewInstance("javafx.scene.robot.Robot", Null)
 robot.RunMethod("mouseMove", Array As Object(x, y))
End sub
 
Last edited:
Upvote 0

petr4ppc

Well-Known Member
Licensed User
Longtime User
Dear friends,

please, can somebody try the code if is it good or bad direction of the solution - how to physicaly secure cursor position and enable mouse clicking on some object? (f.e. windows sw keyboard?)

Thank you
p4ppc
 
Upvote 0
Top