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?
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 Python state-machine design )
精彩评论