I am currently working on a (Python2.5) application which handles input from a game controller. We've designated a button as a shift button to change the mapping (inputtype,value->function) of the other buttons on the fly. The mapping also depends on the mode our application is running in. We are running into lots of hairy edge cases (e.g. how to handle press shift, press button x, release shift, release button x
) and I was wondering if there are any known good structures/architectures/patterns for dealing with this kind of input?
views:
37answers:
1
+2
A:
Satemachines are a good pattern to handle complex inputs.
Here is a machine that handle the above sequence.
You can implement statemachines with switch or state pattern (see http://stackoverflow.com/questions/2101961/python-state-machine-design )
FabienAndre
2010-08-24 15:23:22
We were hoping to avoid an explicit state machine as it will quickly become unwieldly.
Bjartr
2010-08-25 12:33:18
To put in a little more detail: We're dealing with a 10 button controller where one button changes what all the others do when held down. The number of states quickly explodes when dealing with e.g. any button held when shift is pressed, or any two buttons held when shift is pressed, or any three buttons held when shift is pressed. Plus all the converse of shift held before vs. shift pressed after and so on. It just become a tangled mess
Bjartr
2010-09-08 14:48:30