public class EV3Key
extends java.lang.Object
Key
interface for EV3.
The easiest way to get an instance of this class is to use one of the static constants of the Button
class.Modifier and Type | Class and Description |
---|---|
(package private) static class |
EV3Key.KeyType |
Modifier and Type | Field and Description |
---|---|
static int |
BUTTON_ALL |
static int |
BUTTON_BACKSPACE |
static int |
BUTTON_DOWN |
static int |
BUTTON_ENTER |
static int |
BUTTON_ESCAPE |
static int |
BUTTON_LEFT |
static int |
BUTTON_RIGHT |
static int |
BUTTON_UP |
private static int |
EVENT_BUFFER_LEN |
private static int |
KEY_ID_INDEX |
private static int |
KEY_STATE_INDEX |
private static byte |
keyBits |
private static java.lang.Thread |
keyEventReader |
private static java.util.Map<EV3Key.KeyType,java.util.Set<KeyListener>> |
keyListeners |
private EV3Key.KeyType |
keyType |
private static Logger |
log |
(package private) static byte |
STATE_KEY_DOWN |
(package private) static byte |
STATE_KEY_UP |
private static java.lang.String |
SYSTEM_EVENT_PATH |
Constructor and Description |
---|
EV3Key(EV3Key.KeyType keyType)
Create an Instance of EV3Key.
|
EV3Key(int id)
Create an Instance of EV3Key by the numeric key ID.
|
Modifier and Type | Method and Description |
---|---|
void |
addKeyListener(KeyListener keyListener)
Adds a listener for this key's 'pressed' and 'released' events.
|
private static void |
broadcastToListeners(EV3Key.KeyType keyType,
java.util.function.BiConsumer<KeyListener,Key> notificationMethod) |
boolean |
equals(java.lang.Object obj) |
int |
getId()
Returns the ID of this key.
|
java.lang.String |
getName()
Returns the name of this key.
|
int |
hashCode() |
boolean |
isDown()
A non-blocking check of whether this key is currently pressed.
|
boolean |
isUp()
A non-blocking check of whether this key is currently released.
|
(package private) static void |
processKeyEvent(byte keyId,
byte keyState) |
void |
removeKeyListener(KeyListener keyListener)
Removes the given key event listener.
|
void |
simulateEvent(int i) |
java.lang.String |
toString() |
void |
waitForPress()
A blocking call that will return once this key gets pressed.
|
void |
waitForPressAndRelease()
A blocking call that will first wait for this key being pressed and then it waits for this key being released.
|
private static final Logger log
public static final int BUTTON_UP
public static final int BUTTON_DOWN
public static final int BUTTON_LEFT
public static final int BUTTON_RIGHT
public static final int BUTTON_ENTER
public static final int BUTTON_BACKSPACE
public static final int BUTTON_ESCAPE
public static final int BUTTON_ALL
static final byte STATE_KEY_DOWN
static final byte STATE_KEY_UP
private static final java.lang.String SYSTEM_EVENT_PATH
private static final int EVENT_BUFFER_LEN
private static final int KEY_ID_INDEX
private static final int KEY_STATE_INDEX
private static byte keyBits
private static java.util.Map<EV3Key.KeyType,java.util.Set<KeyListener>> keyListeners
private static final java.lang.Thread keyEventReader
private EV3Key.KeyType keyType
public EV3Key(EV3Key.KeyType keyType)
keyType
- public EV3Key(int id)
id
- public int getId()
public boolean isDown()
public boolean isUp()
public void waitForPress()
public void waitForPressAndRelease()
waitForPress()
, this method will always block because this key cannot be already
pressed and released at the same time. At the least, this key will be pressed so this method will only
wait for it to be released.public void addKeyListener(KeyListener keyListener)
Button.ALL
key, the listener will be getting notifications for any key events.keyListener
- public void removeKeyListener(KeyListener keyListener)
keyListener
- public void simulateEvent(int i)
public java.lang.String getName()
public boolean equals(java.lang.Object obj)
equals
in class java.lang.Object
obj
- obj
is an instance of Key
and if the button IDs are the same.public int hashCode()
hashCode
in class java.lang.Object
public java.lang.String toString()
toString
in class java.lang.Object
static void processKeyEvent(byte keyId, byte keyState)
private static void broadcastToListeners(EV3Key.KeyType keyType, java.util.function.BiConsumer<KeyListener,Key> notificationMethod)