kwhat / jnativehook

Global keyboard and mouse listeners for Java.
Other
1.75k stars 347 forks source link

JNativeHook 2.2.2 not working out of the IDE (.jar, .exe, .app) #428

Open FelipeAumannRS opened 1 year ago

FelipeAumannRS commented 1 year ago

Had to move from 1stleg JNativeHook to kwhat since version 2.2.2 supports mac silicon. 1stleg was working in the productive environment flawlessly, instead of kwhat. For some reason, in my IDE it works just fine with all mouse/keyboard listeners, but when running the application from a jar or any kind of executable it just doesn't work. Here's the stacktrace (exception is thrown at

GlobalScreen.setEventDispatcher(new JavaFxDispatchService());

2022-12-01 20:28:27.972 ERROR 18560 --- [lication Thread] com.github.kwhat.jnativehook : URI is not hierarchical Exception in thread "JavaFX Application Thread" java.lang.UnsatisfiedLinkError: URI is not hierarchical at com.github.kwhat.jnativehook.GlobalScreen.<clinit>(GlobalScreen.java:91) at com.nume.main.core.stage.StageInitializer.onApplicationEvent(StageInitializer.java:119) at com.nume.main.core.stage.StageInitializer.onApplicationEvent(StageInitializer.java:37) at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:176) at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:169) at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:143) at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:421) at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:378) at com.nume.main.MirroredMain.lambda$start$1(MirroredMain.java:59) at com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:457) at java.base/java.security.AccessController.doPrivileged(AccessController.java:399) at com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:456) at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96) at com.sun.glass.ui.win.WinApplication._runLoop(Native Method) at com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:184) at java.base/java.lang.Thread.run(Thread.java:833)

Interestingly enough, building the jar with maven Shade plugin enables JNativeHook to work properly, although, for deployment reasons, this plugin isn't an option.

Is there anything else I can do in order to use it without Shade plugin?

Tried on MacOS intel, MacOS silicon, Windows 10, java version 17.0.3 correto. Same behavior for all.

marcin7848 commented 1 year ago

I confirm the issue. I've just tested it using gradle, same problem. Versions: 2.2.0 - 2.2.2 doesn't work outside the IDE. I've also tested the earlier version 2.1.0 - works correctly.

FelipeAumannRS commented 1 year ago

@marcin7848 Thanks for confirming. Unfortunately, a downgrade is not an option since version below 2.2.2 wouldn't work on mac silicon

thewen99 commented 1 year ago

I also encountered this problem. Have you solved it

FelipeAumannRS commented 1 year ago

@thewen99 it seems like the project is abandoned. So bad, jnativehook is outstanding

kwhat commented 1 year ago

it seems like the project is abandoned. So bad, jnativehook is outstanding

99% of the work happens in libuiohook and there is only one of me.

I doubt this is a bug in the library, but the code in question is located here. There is nothing special about it, see why your IDE doesn't like running it.

You really shouldn't be using the library locator in either production or development. It was provided as a convince because Java's library loading is clunky and confusing. You really should be extracting the the native library you need for your target platform and setting the java.library.path property as Sun intended. This convenience feature causes so many bug reports that it will likely be removed from the next version of this library.

SpecialCharacter commented 1 year ago

I tried to install JNativeHook 2.2.2.jar via Eclipse but it did not work. Eclipse sees the .jar file but the check box is not checked, and when I go to the dialogue again, the .jar file is gone.

EtienneLamoureux commented 1 year ago

Same problem here. Anyone found an alternative?

kwhat commented 1 year ago

All you have to do is set up the java.library.path in your IDE and point it to the dll or shared object or dylib inside of the jar ... You probably need to extract it but that's it. The next minor release this library will stop automatically unpacking it for you so you'll be forced to do it even to run the library.

On Tue, Nov 14, 2023, 5:43 PM Etienne Lamoureux @.***> wrote:

Same problem here. Anyone found an alternative?

— Reply to this email directly, view it on GitHub https://github.com/kwhat/jnativehook/issues/428#issuecomment-1811666328, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAFFCREM5P3B3SZFEYOTHXDYEQM33AVCNFSM6AAAAAASRBDK4WVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQMJRGY3DMMZSHA . You are receiving this because you commented.Message ID: @.***>

FelipeAumannRS commented 1 year ago

@kwhat why though? Why this change is necessary? It sounds like a downgrade, I don't get.

toni2ve commented 10 months ago

I faced the same issue when exporting as a runnable jar from Eclipse. The solution that worked for me was to use the following Library handling option "Copy required libraries into a sub-folder next to the generated JAR" while exporting the runnable jar. This option will put the jnativehook-2.2.2.jar and the JNativeHook-2.2.2.x86_64.dll into a folder next to the runnable jar. image

AwesomeYotta commented 10 months ago

I extract the JNativeHook.dll file from jnativehook jar file, and put it in the same directory of my application(single jar file), which is also the working directory, and the program could find the dll file perfectly.

I wish this could be done automatically for this cross platform awesome application, huge work for kwhat, definitly, could this feature be extracted and put in a file for the library users to contribute? altogether cover all the details under all circumstances.