JNativeHook: Global keyboard and mouse listeners for Java.
JNativeHook is a library to provide global keyboard and mouse listeners for Java. This will allow you to listen for global shortcuts or mouse motion that would otherwise be impossible using pure Java. To accomplish this task, JNativeHook leverages platform-dependent native code through Java's native interface to create low-level system-wide hooks and deliver those events to your application.
The following events are available via their respective listeners.
- Key Press Events
- Key Release Events
- Key Typed Events
- Mouse Down Events
- Mouse Up Events
- Mouse Click Events
- Mouse Move Events
- Mouse Drag Events
- Mouse Wheel Events
In addition to global event listeners, this library has the ability to post native events back to the native operating system.
JNativeHook is covered under the GNU Lesser General Public License which is an extension of the GNU General Public License that grants you additional distribution rights. As I understand it, you may use this library in proprietary (closed source) projects so long as it remains an external library with the same binary interface. You may modify the source code of this library to fulfill any proprietary need, as long as those modifications are made available under the terms and conditions of the LGPL. Please consult with a licenced attorney if you have additional licence compatibility questions or concerns.
Binary distribution for JNativeHook can be found at the
releases section of the
project page. Maven users can
to include this library automatically. The nightly builds can be found at the maven
Software and Hardware Requirements
- Java 1.8 - 17
- 256 MB of RAM
- Apple OS X 10.5 - 10.15
- amd64, aarch64
- Enable Access for Assistive Devices
- Windows 2000 - 10
- i586, amd64, arm7
- X11 Linux
- i586, amd64, arm7, aarch64
- Global Keyboard Listener
- Global Mouse Listener
- Global Mouse Wheel Listener
- Thread Safety for AWT, Swing and JavaFX
- Logging and Console Output
- Advanced Library Loading
- Consuming Events (Unsupported)
The graphical example application exists to provide a real-time demonstration of raw output for all available native events. To run the application simply execute the jar file provided. Source code available at src/main/java/com/github/kwhat/jnativehook/example/NativeHookDemo.java.
Up-to-date source code and documentation available at: https://github.com/kwhat/jnativehook/