-
Notifications
You must be signed in to change notification settings - Fork 15
Example 2: Receiving key events
Roland edited this page Sep 9, 2018
·
3 revisions
If a key on the ESD is pressed a KeyEvent is generated. By default those events will not be forwarded.
See tutorial.de.rcblum.stream.deck.Example2_Receiving_key_events.java for the corresponding code.
There are two ways to receive those events:
- Add a StreamKeyListener to the StreamDeck
- Add a StreamItem to the StreamDeck
This example will cover option number 1.
Includes:
import de.rcblum.stream.deck.device.IStreamDeck;
import de.rcblum.stream.deck.device.StreamDeckDevices;
import de.rcblum.stream.deck.event.KeyEvent;
import de.rcblum.stream.deck.event.StreamKeyListener;Create the StreamKeyListener:
public class ExampleListener implements StreamKeyListener {
public void onKeyEvent(KeyEvent event) {
switch(event.getType()) {
case OFF_DISPLAY :
System.out.println(event.getKeyId() + ": taken off display");
break;
case ON_DISPLAY:
System.out.println(event.getKeyId() + ": put on display");
break;
case PRESSED:
System.out.println(event.getKeyId() + ": pressed");
break;
case RELEASED_CLICKED:
System.out.println(event.getKeyId() + ": released/clicked");
break;
}
}
}Add the Listener to the stream deck:
// Get the first connected (or software) ESD:
IStreamDeck streamDeck = StreamDeckDevices.getStreamDeck();
// Reset the ESD so we can display our icon on it:
streamDeck.reset();
// Set the brightness to 75%
streamDeck.setBrightness(75);
// Add the Listener to the stream deck:
streamDeck.addKeyListener(new ExampleListener());Thats it. Now when you press a key on the ESD something along the following should be displayed:
0: pressed
0: released/clicked
5: pressed
5: released/clicked
11: pressed
11: released/clicked