I've been using a certain dependency to implement event listeners for mouse and keyboard tracking on Windows and Mac systems with Intel chips. However, upon transitioning to a Mac with an M1 chip (ARM architecture - Apple Silicon chip), I encounter an exception. Could you suggest an alternative library suitable for this situation?
GlobalScreen.registerNativeHook();
GlobalScreen.addNativeKeyListener(this);
GlobalScreen.addNativeMouseListener(this);
GlobalScreen.addNativeMouseMotionListener(this);
GlobalScreen.addNativeMouseWheelListener(this);
<dependency>
<groupId>com.1stleg</groupId>
<artifactId>jnativehook</artifactId>
<version>2.1.0</version>
</dependency>
Dependency which is working fine for Intel chip
Apr 01, 2024 11:26:16 PM org.jnativehook.DefaultLibraryLocator getLibraries
SEVERE: Unable to extract the native library /org/jnativehook/lib/darwin/unsupported/libJNativeHook.dylib!
Exception in thread "JavaFX Application Thread" java.lang.UnsatisfiedLinkError: 'java.lang.Integer org.jnativehook.GlobalScreen.getAutoRepeatRate()'
at org.jnativehook.GlobalScreen.getAutoRepeatRate(Native Method)
at org.jnativehook.GlobalScreen.<clinit>(Unknown Source)
at com.staffViz.controllers.main_controllers.RunningTrackerModuleController.itemStateChanged(RunningTrackerModuleController.java:177)
at com.staffViz.controllers.main_controllers.RunningTrackerModuleController.initialize(RunningTrackerModuleController.java:121)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2670)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2563)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2531)
at com.staffViz.controllers.main_controllers.ProjectMainScreenController.startTracker(ProjectMainScreenController.java:1362)
at com.staffViz.listViewCell.TaskCell.startTracker(TaskCell.java:325)
at com.staffViz.listViewCell.TaskCell.lambda$updateItem$7(TaskCell.java:168)
at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:232)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:189)
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.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.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.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:198)
at javafx.scene.Scene$ClickGenerator.postProcess(Scene.java:3688)
at javafx.scene.Scene$MouseHandler.process(Scene.java:3993)
at javafx.scene.Scene.processMouseEvent(Scene.java:1890)
at javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2708)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:411)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:301)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent$2(GlassViewEventHandler.java:450)
at com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:424)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:449)
at com.sun.glass.ui.View.handleMouseEvent(View.java:551)
at com.sun.glass.ui.View.notifyMouse(View.java:937)
at com.sun.glass.ui.mac.MacView.notifyMouse(MacView.java:127)
Native code needs to be compiled for the specific architecture and operating system where it will be executed. You can not just use an Intel library in an ARM CPU. You need to get the appropriate build from the provider, or if you have the source build it yourself.
JNativeHook 2.1.0 is too old and didn't include macOS (Darwin) with ARM as a target. Apple M1 chip based computers were not even released at that time.
You need to update to the current release, 2.2.2 at this time, which supports the Darwin/aarch64 target. The distribution includes the appropriate version of the native library.