public class GlobalScreen extends Object
This class also handles the loading, unpacking and communication with the native library. That includes registering and un-registering the native hook with the underlying operating system and adding global keyboard and mouse listeners.
| Modifier and Type | Class and Description |
|---|---|
protected static class |
GlobalScreen.NativeHookThread
Specialized thread implementation for the native hook.
|
| Modifier and Type | Field and Description |
|---|---|
protected static ExecutorService |
eventExecutor
The service to dispatch events.
|
protected static EventListenerList |
eventListeners
The list of event listeners to notify.
|
protected static GlobalScreen.NativeHookThread |
hookThread
The service to control the hook.
|
protected static Logger |
log
Logging service for the native library.
|
| Modifier | Constructor and Description |
|---|---|
protected |
GlobalScreen() |
| Modifier and Type | Method and Description |
|---|---|
static void |
addNativeKeyListener(NativeKeyListener listener)
Adds the specified native key listener to receive key events from the
native system.
|
static void |
addNativeMouseListener(NativeMouseListener listener)
Adds the specified native mouse listener to receive mouse events from the
native system.
|
static void |
addNativeMouseMotionListener(NativeMouseMotionListener listener)
Adds the specified native mouse motion listener to receive mouse motion
events from the native system.
|
static void |
addNativeMouseWheelListener(NativeMouseWheelListener listener)
Adds the specified native mouse wheel listener to receive mouse wheel
events from the native system.
|
static Integer |
getAutoRepeatDelay()
Retrieves the keyboard auto repeat delay.
|
static Integer |
getAutoRepeatRate()
Retrieves the keyboard auto repeat rate.
|
static Integer |
getMultiClickIterval()
Retrieves the double/triple click interval in milliseconds.
|
static NativeMonitorInfo[] |
getNativeMonitors()
Get information about the native monitor configuration and layout.
|
static Integer |
getPointerAccelerationMultiplier()
Retrieves the mouse acceleration multiplier.
|
static Integer |
getPointerAccelerationThreshold()
Retrieves the mouse acceleration threshold.
|
static Integer |
getPointerSensitivity()
Retrieves the mouse sensitivity.
|
static boolean |
isNativeHookRegistered()
Returns
true if the native hook is currently registered. |
static void |
postNativeEvent(NativeInputEvent event)
Add a
NativeInputEvent to the operating system's event queue. |
static void |
registerNativeHook()
Enable the native hook.
|
static void |
removeNativeKeyListener(NativeKeyListener listener)
Removes the specified native key listener so that it no longer receives
key events from the native system.
|
static void |
removeNativeMouseListener(NativeMouseListener listener)
Removes the specified native mouse listener so that it no longer receives
mouse events from the native system.
|
static void |
removeNativeMouseMotionListener(NativeMouseMotionListener listener)
Removes the specified native mouse motion listener so that it no longer
receives mouse motion events from the native system.
|
static void |
removeNativeMouseWheelListener(NativeMouseWheelListener listener)
Removes the specified native mouse wheel listener so that it no longer
receives mouse wheel events from the native system.
|
static void |
setEventDispatcher(ExecutorService dispatcher)
Set a different executor service for native event delivery.
|
static void |
unregisterNativeHook()
Disable the native hook if it is currently registered.
|
protected static Logger log
protected static GlobalScreen.NativeHookThread hookThread
protected static ExecutorService eventExecutor
protected static EventListenerList eventListeners
public static void addNativeKeyListener(NativeKeyListener listener)
listener - a native key listener objectpublic static void removeNativeKeyListener(NativeKeyListener listener)
listener - a native key listener objectpublic static void addNativeMouseListener(NativeMouseListener listener)
listener - a native mouse listener objectpublic static void removeNativeMouseListener(NativeMouseListener listener)
listener - a native mouse listener objectpublic static void addNativeMouseMotionListener(NativeMouseMotionListener listener)
listener - a native mouse motion listener objectpublic static void removeNativeMouseMotionListener(NativeMouseMotionListener listener)
listener - a native mouse motion listener objectpublic static void addNativeMouseWheelListener(NativeMouseWheelListener listener)
listener - a native mouse wheel listener objectpublic static void removeNativeMouseWheelListener(NativeMouseWheelListener listener)
listener - a native mouse wheel listener objectpublic static NativeMonitorInfo[] getNativeMonitors()
NativeMonitorInfo objects.public static Integer getAutoRepeatRate()
Integer or null.public static Integer getAutoRepeatDelay()
Integer or null.public static Integer getPointerAccelerationMultiplier()
Integer or null.public static Integer getPointerAccelerationThreshold()
Integer or null.public static Integer getPointerSensitivity()
Integer or null.public static Integer getMultiClickIterval()
Integer or null.public static void registerNativeHook()
throws NativeHookException
Note: This method will throw a NativeHookException
if specific operating system feature is unavailable or disabled.
For example: Access for assistive devices is unchecked in the Universal
Access section of the System Preferences on Apple's OS X platform or
Load "record" is missing for the xorg.conf file on
Unix/Linux/Solaris platforms.
NativeHookException - problem registering the native hook with the underlying operating system.public static void unregisterNativeHook()
throws NativeHookException
NativeHookException - hook interrupted by Java.public static boolean isNativeHookRegistered()
true if the native hook is currently registered.public static void postNativeEvent(NativeInputEvent event)
NativeInputEvent to the operating system's event queue.
Each type of NativeInputEvent is processed according to its
event id.
For both NATIVE_KEY_PRESSED and
NATIVE_KEY_RELEASED events, the virtual keycode and modifier
mask are used in the creation of the native event. Please note that some
platforms may generate NATIVE_KEY_PRESSED and
NATIVE_KEY_RELEASED events for each required modifier.
NATIVE_KEY_TYPED events will first translate the associated
keyChar to its respective virtual code and then produce a
NATIVE_KEY_PRESSED followed by a NATIVE_KEY_RELEASED
event using that virtual code. If the JNativeHook is unable to translate
the keyChar to its respective virtual code, the event is ignored.
NativeMouseEvents are processed in much the same way as the
NativeKeyEvents. Both NATIVE_MOUSE_PRESSED and
NATIVE_MOUSE_RELEASED produce events corresponding to the
event's button code. Keyboard modifiers may be used in conjunction with
button press and release events, however, they might produce events for each
modifier. NATIVE_MOUSE_CLICKED events produce a
NATIVE_MOUSE_PRESSED event followed by a
NATIVE_MOUSE_RELEASED for the assigned event button.
NATIVE_MOUSE_DRAGGED and NATIVE_MOUSE_MOVED events
are handled identically. In order to produce a NATIVE_MOUSE_DRAGGED
event, you must specify a button modifier mask that contains at least one
button modifier and assign it to the event. Failure to do so will produce a
NATIVE_MOUSE_MOVED event even if the event id was set to
NATIVE_MOUSE_DRAGGED.
NATIVE_MOUSE_WHEEL events are identical to
NATIVE_MOUSE_PRESSED events. Wheel events will only produce
pressed events and will never produce NATIVE_MOUSE_RELEASED,
NATIVE_MOUSE_DRAGGED or NATIVE_MOUSE_MOVED
event - the NativeInputEvent sent to the native system.public static void setEventDispatcher(ExecutorService dispatcher)
ExecutorService.
Note: Using null as an ExecutorService will cause all
delivered events to be discarded until a valid ExecutorService
is set.
dispatcher - The ExecutorService used to dispatch native events.ExecutorService,
Executors.newSingleThreadExecutor()Copyright © 2006-2017 ${project.vendor}. All Rights Received.