Class GlobalMouseHook


  • public class GlobalMouseHook
    extends Object
    • Constructor Detail

      • GlobalMouseHook

        public GlobalMouseHook()
                        throws UnsatisfiedLinkError
        Instantiate a new GlobalMouseHook. The constructor first tries to load the native library. On failure a UnsatisfiedLinkError is thrown. Afterwards the native mouse hook is initialized. A RuntimeException is 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 failed
        RuntimeException - Thrown if registering the low-level mouse hook failed
      • GlobalMouseHook

        public GlobalMouseHook​(boolean raw)
                        throws UnsatisfiedLinkError
        Instantiate 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 failed
        RuntimeException - 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.