Class InputDevice

  • All Implemented Interfaces:
    InputDevicePath

    public class InputDevice
    extends Object
    implements InputDevicePath
    InputDevice InputDevice read events from input devices provided by the event device (evdev) interface of the linux kernel. The character devices in the directory /dev/input/eventX are read and decoded. You can attach a listener to an event with given type and code.
    Author:
    Christian Paul
    • Constructor Detail

      • InputDevice

        public InputDevice​(String path)
        Instantiates new InputDevice.
        Parameters:
        path - od the input device to read
    • Method Detail

      • getPath

        public String getPath()
        Returns:
        the path of the input device
      • setConnectionDelay

        public void setConnectionDelay​(int connectionDelay)
        Set delay before next connecting attempt in milliseconds
        Parameters:
        connectionDelay - delay in milliseconds
      • getConnectionDelay

        public int getConnectionDelay()
        Get the delay before next connecting attempt in milliseconds
        Returns:
        the delay in milliseconds
      • getMaxConnectionAttemps

        public int getMaxConnectionAttemps()
        Get the maximal attempts of open input device path
        Returns:
        maximal attempts
      • setMaxConnectionAttemps

        public void setMaxConnectionAttemps​(int maxConnectionAttemps)
        Set the maximal attempts of open input device path
        Parameters:
        maxConnectionAttemps - maximal attempts
      • onEvent

        public void onEvent​(EventListener listener)
        Sets a global listener that listen to all events. It's only possible to set one global listener.
        Parameters:
        listener - instance of EventListener that should receive events
      • onEvent

        public void onEvent​(EventType type,
                            int code,
                            EventListener listener)
        Sets an event listener for given event type and code. It's only possible to set one RawListener for one tuple of type and code.
        Parameters:
        type - the EventType to listen for
        code - the code of the event
        listener - instance of EventLister that should receive events
      • onEvent

        public void onEvent​(EventType type,
                            int code,
                            Predicate<Integer> predicate,
                            EventListener listener)
        Sets an event listener for given event type and code. It's only possible to set one RawListener for one tuple of type and code.
        Parameters:
        type - the EventType to listen for
        code - the code of the event
        predicate - predicate to fulfil
        listener - instance of EventLister that should receive events
      • onKey

        public void onKey​(int code,
                          EventListener listener)
        Sets an event listener for an key event and code. It's only possible to set one RawListener for one tuple of type and code.
        Parameters:
        code - the code of the event
        listener - instance of EventLister that should receive events
      • onKey

        public void onKey​(int code,
                          Predicate<Integer> predicate,
                          EventListener listener)
        Sets an event listener for an key event and code. It's only possible to set one RawListener for one tuple of type and code.
        Parameters:
        code - the code of the event
        predicate - predicate to fulfil
        listener - instance of EventLister that should receive events
      • onAxis

        public void onAxis​(int code,
                           EventListener listener)
        Sets an event listener for an axis event and code. It's only possible to set one RawListener for one tuple of type and code.
        Parameters:
        code - the code of the event
        listener - instance of EventLister that should receive events
      • onAxis

        public void onAxis​(int code,
                           Predicate<Integer> predicate,
                           EventListener listener)
        Sets an event listener for an axis event and code. It's only possible to set one RawListener for one tuple of type and code.
        Parameters:
        code - the code of the event
        predicate - predicate to fulfil
        listener - instance of EventLister that should receive events
      • onAttach

        public void onAttach​(AttachListener listener)
        Sets an listener to be notfied if the input device is attached.
        Parameters:
        listener - AttachedListener to set
      • onDetach

        public void onDetach​(DetachListener listener)
        Sets an listener to be notfied if the input device is detached.
        Parameters:
        listener - DetachedListener to set
      • onDetach

        public void onDetach()
        Called if input device is detached. Calls a added DetachListener and stops reading events from the input device.
      • start

        public void start()
        Starts monitoring and reading the input device. Runs until ends with finish.
      • finish

        public void finish()
        Shutdown and finish