Bjroos
Posts: 1
Joined: Sat Jul 02, 2016 3:31 pm

getch() freezes up - Help

Sat Jul 02, 2016 11:18 pm

Hi,

I'm a dad trying to help my 10 year old son run a robot off of the Raspberry Pi. The robot is running fine, but he would really prefer to drive it with the arrow keys. We have tried the getch() command a variety of ways including through the getch() module and the curses module. Unfortunately to program just kind of gets stuck when getch() is called. Example program using the getch() command is as follows.:

Import getch
print('Push an arrow key to drive the robot')
char = getch.getch()
print('Thank you')

This is just a test program to test the function. When this program is run, the shell window pops up, the cursor moves to the following line, "Push an arrow key to drive the robot" prints....and you can type in anything you want on the screen after that. Everything is echoed. However, the program never gets to the 4th line of the code, regardless of how many characters are input. "Thank you" never prints. It seems to get stuck in an infinite loop of some sort.

In order to stop the program, you must click the X in the upper right corner of the shell. When you do this, a pop-up lets you know that the program is still running and asks if you want to kill it.....so we kill it.

We have tried to use several of the options (objects) for the getch() command provided by forums online, but nothing seems to do what we want it to do. We are running Raspberry PI with Python 3.2.

We would appreciate any tips for making getch() work.

Thank you

Aydan
Posts: 729
Joined: Fri Apr 13, 2012 11:48 am
Location: Germany, near Lake Constance

Re: getch() freezes up - Help

Wed Jul 06, 2016 2:28 pm

From your description I assume you use IDLE to start the program.
Can you try to start the programm from a terminal window?
I suspect that the key events are not correctly forwarded to the python process.
getch() should not show an echo of the keys pressed on the commandline.

Regards
Aydan

Return to “Python”