Package xyz.cp74.evdev
Class InputDevice
- java.lang.Object
-
- xyz.cp74.evdev.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
-
-
Field Summary
-
Fields inherited from interface xyz.cp74.evdev.InputDevicePath
EVENT0, EVENT1, EVENT10, EVENT11, EVENT12, EVENT13, EVENT14, EVENT15, EVENT16, EVENT17, EVENT18, EVENT19, EVENT2, EVENT20, EVENT21, EVENT22, EVENT23, EVENT24, EVENT25, EVENT26, EVENT27, EVENT28, EVENT29, EVENT3, EVENT30, EVENT31, EVENT32, EVENT33, EVENT34, EVENT35, EVENT36, EVENT37, EVENT38, EVENT39, EVENT4, EVENT5, EVENT6, EVENT7, EVENT8, EVENT9
-
-
Constructor Summary
Constructors Constructor Description InputDevice(String path)Instantiates new InputDevice.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidfinish()Shutdown and finishintgetConnectionDelay()Get the delay before next connecting attempt in millisecondsintgetMaxConnectionAttemps()Get the maximal attempts of open input device pathStringgetPath()voidonAttach(AttachListener listener)Sets an listener to be notfied if the input device is attached.voidonAxis(int code, Predicate<Integer> predicate, EventListener listener)Sets an event listener for an axis event and code.voidonAxis(int code, EventListener listener)Sets an event listener for an axis event and code.voidonDetach()Called if input device is detached.voidonDetach(DetachListener listener)Sets an listener to be notfied if the input device is detached.voidonEvent(EventListener listener)Sets a global listener that listen to all events.voidonEvent(EventType type, int code, Predicate<Integer> predicate, EventListener listener)Sets an event listener for given event type and code.voidonEvent(EventType type, int code, EventListener listener)Sets an event listener for given event type and code.voidonKey(int code, Predicate<Integer> predicate, EventListener listener)Sets an event listener for an key event and code.voidonKey(int code, EventListener listener)Sets an event listener for an key event and code.voidsetConnectionDelay(int connectionDelay)Set delay before next connecting attempt in millisecondsvoidsetMaxConnectionAttemps(int maxConnectionAttemps)Set the maximal attempts of open input device pathvoidstart()Starts monitoring and reading the input device.
-
-
-
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 forcode- the code of the eventlistener- 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 forcode- the code of the eventpredicate- predicate to fulfillistener- 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 eventlistener- 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 eventpredicate- predicate to fulfillistener- 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 eventlistener- 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 eventpredicate- predicate to fulfillistener- 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
-
-