Keyboard Control · Study
English translation
Execution conditions
Reproduce behavior using an input event list. Connecting a real keyboard or device is a separate step that connects the same processing function to the event receiver.
Topics covered
To stop a moving device, define its behavior when a key is released or communication is lost, as well as when a key is pressed.
Overall workflow
Image/input events → coordinate/validity checks → bounded commands → path/failure checks
From input events to state
A key press sets a velocity command, and a release clears it. Adding distance for every received event can make movement depend on the number of repeated inputs and processing speed. Maintain state and integrate position over time intervals.
Command validity duration
Continuing at the last velocity when input stops is dangerous. Track the last reception time and use a timeout to replace stale commands with a stop. Test normal termination, communication gaps, and repeated inputs separately.
Worked example
s, key=[w,w,release,d,quit,w]. Set w=(1,0) and d=(0,-1) m/s.
events=list(zip([0,.1,.2,.3,.4,.5],['w','w','release','d','quit','w']))
key_velocity={'w':(1.,0.),'s':(-1.,0.),'a':(0.,1.),'d':(0.,-1.)}
Reference example
View more examples