Robot using Keypress input (without enter)[SOLVED]


#1

Hello, I am working on a BrickPi robot project and need some help. What I would like for the robot to be able to do is if the user presses and holds the “w” key, then the robot will move forward. I would like to eliminate the need for the raw input, which requires the enter key to be held down after you press the desired direction key. How can I do this? I tried to use the msvcrt and getch, since as I read they work for windows platforms, but is there any way I can do this with Linux (raspberry pi)?

I would very much appreciate your help, as I simply cannot get it to work.

Thank you,

Radu Teodorescu


#2

Funnily Scratch is much more suited to this type of keyboard input than Python. It can be done in Python but it’s not trivial and you can put your Pi in a weird mode. You have to look at the termios library.
Lately another library called input has got published but I have no experience with it.

Your best bet however is going through PyGame. This library has good keyboard handling.


#3

Thank you for your help, after a bit of searching i was able to put together a program with the termios that does what i wanted. As for the weird mode I saw what you meant since even after exiting terminal (and the program) the CPU load indicator still remained at 100%. But so far nothing major has happened to affect the functioning of the robot.

Thanks again,

Radu


#4