If you are using RobotBuilder then you can to a "whenPressed" action...
https://wpilib.screenstepslive.com/s...e-to-a-command
If you are using command classes yourself there is a Button class you could wire into the scheduler.
If you are just writing straight java, I usually just copy/paste the following...
Code:
//instance variables
boolean [] btns = new boolean [] {false,false,false,false,false};
boolean [] last = new boolean [] {false,false,false,false,false};
Code:
//get latest
public void teleopPeriodic() {
btns[1] = _joy.getRawButton(1);
btns[2] = _joy.getRawButton(2);
btns[3] = _joy.getRawButton(3);
btns[4] = _joy.getRawButton(4);
Code:
if(!last[3] && btns[3]){
//btn3 just pressed, do something
}
Code:
// bottom of teleop save all btns into last
for(i=0;i<last.length;++i)
last[i] = btns[i];