Hi! i’m using the library game control plus to interact with on sketch in processing. what i’m trying to do is that if i press a button, change his state to the contrary, like in the code below. i want to create or use a function like the keyPressed() but with the keys of the controller
import net.java.games.input.*;
import org.gamecontrolplus.*;
import org.gamecontrolplus.gui.*;
ControlIO control;
ControlDevice xbox;
boolean s = false;
boolean onAndOff = false;
long previousMillis = 0;
long startMillis = 0;
void setup() {
size(500, 500);
control = ControlIO.getInstance(this);
xbox = control.getMatchedDevice("XboxController");
if (xbox == null) {
println("no esta conectado el control");
System.exit(-1);
}
}
void draw() {
background(0);
startMillis = millis();
s = xbox.getButton("Start").pressed();
if ( (startMillis - previousMillis) >= 20) {
if (s == true) {
onAndOff =! onAndOff;
}
previousMillis = startMillis;
}
println(onAndOff);
}
i used the millis function because i assume that at pressing the key, it have to wait some time in order to read only 1 value.
Greetings!