B4J Question NativeHookB4j - UI application

Ang3ls

Member
Licensed User
Longtime User
NativeHookB4j
there is a way to make the library into one ui application?

Non-UI Works well:

B4X:
Sub AppStart(Args() As String)
   NH.Initialize("NH", Me)
   NH.startNativeMouseInputListener
   NH.enableKillCode 
   NH.EnableEventConsumption
   StartMessageLoop
End Sub

Sub NH_NativeMouseClicked(nme As NativeMouseEvent) As Boolean
    Log("CLICK")
    Return True
End Sub

Can i get the same functionality in an UI application ?
TNXXXXXXXXX
 

Ang3ls

Member
Licensed User
Longtime User
yes i have checked
B4X:
This library works in UI apps. However, you won't be able to directly access UI elements from the NativeHook events since they run in a separate thread. Instead, you'll have to use Thread.RunOnGuiThread() to access UI elements (from the Threading library). I don't think this is your problem, though.

but without the StartMessageLoop i am not able to intercept mouse click...
 
Upvote 0

Roycefer

Well-Known Member
Licensed User
Longtime User
UI applications automatically create their own message loops, you don't need to start one explicitly. See this project for an example of a UI application that uses jNativeHookB4J: https://b4x.com/android/forum/threads/jvm-kvm-raspi-etc-open-source.61029/ (specifically the Controller portion). I start the NH Listeners in a button_Click event sub. Nothing really magical or special going on.

If you're getting Exceptions, make sure to post them.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…