I would like to create a python program to detect when a certain key (W,A,S,D) is pressed so for example, while the w key is pressed, the def forward() is activated and when it is let go, it stops the motor. How would I do this so that as soon as the pi boots up, my keystrokes are detected and the program responds accordingly?
#!/usr/bin/python import explorerhat import sys, tty, termios, time def left(): explorerhat.motor.one.forward(75) def right(): explorerhat.motor.one.backward(75) while True: char = input() if(char=="a"): left() if(char=="d"): right() if(char=="x"): break char = "" explorerhat.motor.one.stop()
Thanks! This is to control a little robot I'm building.