public class Button
extends java.lang.Object
Button.ENTER.waitForPressAndRelease(); Sound.playTone(1000, 1);Notions: The API is designed around two notions: states (up / down) and events (press / release). It is said that a button is pressed (press event), if its state changes from up to down. Similarly, it is said that a button is released (release event), if its states changed from down to up. Thread Safety: All methods that return buttons states can be used safely from multiple threads, even while a call to one of the waitFor* methods active. However, it is not safe to invoke waitFor* methods in parallel from different threads. This includes the waitFor* methods of different buttons. For example Button.ENTER.waitForPress() must not be invoked in parallel to Button.ESCAPE.waitForPress() or the static Button.waitForAnyEvent(). In case this is needed, it is strongly recommended that you write your own Thread, which waits for button events and dispatches the events to anyone who's interested.
Modifier and Type | Field and Description |
---|---|
static Key |
DOWN
The Down button.
|
static Key |
ENTER
The Enter button.
|
static Key |
ESCAPE
The Escape button.
|
static java.lang.String |
FREQ_SETTING |
static int |
ID_ALL |
static int |
ID_DOWN |
static int |
ID_ENTER |
static int |
ID_ESCAPE |
static int |
ID_LEFT |
static int |
ID_RIGHT |
static int |
ID_UP |
static Keys |
keys |
static Key |
LEFT
The Left button.
|
static java.lang.String |
LEN_SETTING |
static Key |
RIGHT
The Right button.
|
static Key |
UP
The Up button.
|
static java.lang.String |
VOL_SETTING |
Modifier and Type | Method and Description |
---|---|
static void |
discardEvents()
This method discards any events.
|
static int |
getButtons()
Low-level API that reads status of buttons.
|
static int |
getKeyClickLength()
Return the current key click length.
|
static int |
getKeyClickTone(int key)
Return the click freq for a particular key.
|
static int |
getKeyClickVolume()
Return the current key click volume.
|
static void |
LEDPattern(int pattern) |
static int |
readButtons()
Low-level API that reads status of buttons.
|
static void |
setKeyClickLength(int len)
Set the len used for key clicks
|
static void |
setKeyClickTone(int key,
int freq)
Set the frequency used for a particular key.
|
static void |
setKeyClickVolume(int vol)
Set the volume used for key clicks
|
static int |
waitForAnyEvent()
Waits for some button to be pressed or released.
|
static int |
waitForAnyEvent(int timeout)
Waits for some button to be pressed or released.
|
static int |
waitForAnyPress()
Waits for some button to be pressed.
|
static int |
waitForAnyPress(int timeout)
Waits for some button to be pressed.
|
public static final int ID_UP
public static final int ID_ENTER
public static final int ID_DOWN
public static final int ID_RIGHT
public static final int ID_LEFT
public static final int ID_ESCAPE
public static final int ID_ALL
public static final java.lang.String VOL_SETTING
public static final java.lang.String LEN_SETTING
public static final java.lang.String FREQ_SETTING
public static final Key ENTER
public static final Key LEFT
public static final Key RIGHT
public static final Key ESCAPE
public static final Key UP
public static final Key DOWN
public static final Keys keys
public static void discardEvents()
readButtons()
,
this method doesn't beep if a button is pressed.public static int waitForAnyEvent()
public static int waitForAnyEvent(int timeout)
public static int waitForAnyPress(int timeout)
timeout
- The maximum number of milliseconds to waitpublic static int waitForAnyPress()
public static int getButtons()
public static int readButtons()
public static void setKeyClickVolume(int vol)
vol
- public static int getKeyClickVolume()
public static void setKeyClickLength(int len)
len
- the click durationpublic static int getKeyClickLength()
public static void setKeyClickTone(int key, int freq)
key
- the NXT keyfreq
- the frequencypublic static int getKeyClickTone(int key)
key
- The key to obtain the tone forpublic static void LEDPattern(int pattern)