Package lc.kra.system.mouse
Class GlobalMouseHook
- java.lang.Object
-
- lc.kra.system.mouse.GlobalMouseHook
-
public class GlobalMouseHook extends Object
-
-
Constructor Summary
Constructors Constructor Description GlobalMouseHook()Instantiate a new GlobalMouseHook.GlobalMouseHook(boolean raw)Instantiate a new GlobalMouseHook.GlobalMouseHook(GlobalHookMode mode)Instantiate a new GlobalMouseHook.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddMouseListener(GlobalMouseListener listener)Adds a global mouse listenerbooleanisAlive()Checks whether the mouse hook is still alive and capturing inputsstatic Map<Long,String>listMice()Lists all connected micevoidremoveMouseListener(GlobalMouseListener listener)Removes a global mouse listenervoidshutdownHook()Shutdown the mouse hook in case it is still alive.
-
-
-
Constructor Detail
-
GlobalMouseHook
public GlobalMouseHook() throws UnsatisfiedLinkErrorInstantiate a new GlobalMouseHook. The constructor first tries to load the native library. On failure aUnsatisfiedLinkErroris thrown. Afterwards the native mouse hook is initialized. ARuntimeExceptionis raised in case the hook could not be established. Two separate threads are started by the class. The HookThread and a separate EventDispatcherThread.- Throws:
UnsatisfiedLinkError- Thrown if loading the native library failedRuntimeException- Thrown if registering the low-level mouse hook failed
-
GlobalMouseHook
public GlobalMouseHook(boolean raw) throws UnsatisfiedLinkErrorInstantiate a new GlobalMouseHook.- Parameters:
raw- Use raw input, instead of a low-level system hook. Raw input will provide additional information of the device, but only give relative X/Y positions- Throws:
UnsatisfiedLinkError- Thrown if loading the native library failedRuntimeException- Thrown if registering the low-level keyboard hook failed- See Also:
GlobalMouseHook()
-
GlobalMouseHook
public GlobalMouseHook(GlobalHookMode mode) throws UnsatisfiedLinkError
Instantiate a new GlobalMouseHook.- Parameters:
mode- The mode to capture the input- Throws:
UnsatisfiedLinkError- Thrown if loading the native library failedRuntimeException- Thrown if registering the low-level keyboard hook failed- See Also:
GlobalMouseHook()
-
-
Method Detail
-
addMouseListener
public void addMouseListener(GlobalMouseListener listener)
Adds a global mouse listener- Parameters:
listener- The listener to add
-
removeMouseListener
public void removeMouseListener(GlobalMouseListener listener)
Removes a global mouse listener- Parameters:
listener- The listener to remove
-
isAlive
public boolean isAlive()
Checks whether the mouse hook is still alive and capturing inputs- Returns:
- true if the mouse hook is alive
-
shutdownHook
public void shutdownHook()
Shutdown the mouse hook in case it is still alive. This method does nothing if the hook already shut down and will block until shut down.
-
listMice
public static Map<Long,String> listMice() throws UnsatisfiedLinkError
Lists all connected mice- Returns:
- A map of device handles and display names
- Throws:
UnsatisfiedLinkError
-
-