We're currently programming a robot using pygame lib, python, raspberryPI, and adafruit motor hat. Here is example of what we do to increase the speed of the motors from 0 to 100:
for i in range(100):
motor.run(i)
This code is inside definitions for moving forward, backward and around and it is used when a keyboard button is pressed. However, we want to interrupt the "for" loop when the KEY is release.