views:

37

answers:

1

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?

+2  A: 

Satemachines are a good pattern to handle complex inputs.

Here is a machine that handle the above sequence.

state machine picture

You can implement statemachines with switch or state pattern (see http://stackoverflow.com/questions/2101961/python-state-machine-design )

FabienAndre
We were hoping to avoid an explicit state machine as it will quickly become unwieldly.
Bjartr
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