Using Joystick buttons using states

C++

Public Domain

In code that is constantly running (games, robots), making a button do something can be complicated, because if your code relys on a user holding down the trigger on a joystick they might hold it down enough for the code to be cycled through more than one time. This takes care of that problem.

Download (right click, save as, rename as appropriate)

Embed

1
2
3
4
5
6
7
8
if(triggerState = joyStick->GetTrigger()) {
				if(triggerState != lastTriggerState) {
                                           // Do what needs to be done here.
					}
				}
			}

triggerState = lastTriggerState;