You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[](https://ci.appveyor.com/project/kristian/system-hook)
2
+
3
+
Java (low-level) System Hook provides a very light-weight global keyboard and mouse listener for Java. Generally keyboard and mouse events in Java work, only if the registered component is in focus. For example, in case any window looses its focus (e.g. when minimized), it stops receiving any more keyboard or mouse events. Through a low-level system-wide hook the *global keyboard / mouse hook* is able to deliver those events regardless.
4
+
5
+
The *Java (low-level) System Hook* comes bundled with native libraries (for Windows 32 & 64 bit) to register the hooks via the Java Native Interface (JNI). The libraries are load dynamically depending on the version and architecture of your operating system. The libraries to track the keyboard and mouse events can be loaded and used separately.
6
+
7
+
Using the `GlobalKeyboardHook` class a `GlobalKeyListener` or the adapter class `GlobalKeyAdapter` can be registered to listen to `keyPressed` and `keyReleased` events like so:
} catch(InterruptedException e) { /* nothing to do here */ }
33
+
finally { keyboardHook.shutdownHook(); }
34
+
}
35
+
}
36
+
```
37
+
38
+
Using the `GlobalMouseHook` class a `GlobalMouseListener` or the adapter class `GlobalMouseAdapter` can be registered to listen to `mousePressed`, `mouseReleased`, `mouseMoved` and `mouseWheel` events like so:
} catch(InterruptedException e) { /* nothing to do here */ }
71
+
finally { mouseHook.shutdownHook(); }
72
+
}
73
+
}
74
+
```
75
+
76
+
Please find some background information about this framework [on my blog](http://kra.lc/blog/2016/02/java-global-system-hook/).
77
+
78
+
Usage
79
+
-----
80
+
81
+
Feel free to use the classes `lc.kra.system.keyboard.GobalKeyboardHook` and `lc.kra.system.mouse.GlobalMouseHook` by coping the `.java` files to your project. Alternatively check the [**releases section**](https://github.com/kristian/system-hook/releases) for pre-bundled Java archives (JAR).
82
+
83
+
The `LibraryLoader` will first attempt to load the native libraries from the `java.library.path` and fall back checking the archives `/lc/kra/system/lib` package, if no libraries where found.
84
+
85
+
### Maven Dependency
86
+
You can include `system-hook` from this GitHub repository by adding this dependency to your `pom.xml`:
87
+
88
+
```xml
89
+
<dependency>
90
+
<groupId>lc.kra.system</groupId>
91
+
<artifactId>system-hook</artifactId>
92
+
<version>2.0</version>
93
+
</dependency>
94
+
```
95
+
96
+
Additionally you will have to add the following repository to your `pom.xml`:
<failmessage="Could not find ant.jni.include folder. Please set your JAVA_HOME environment variable to the root of your JDK directory or manually set the ant.jni.include to the location of the Java JNI header files.">
0 commit comments