>The code in capture_key.py may look a bit scary, but just as I took it >without bothering the details you can take the resulting module without >caring about the code in it. Alternatively you can search
>https://pypi.python.org Thanks for the link. I realy appreciate it. Can you also tell me what I am looking for in https://pypi.python.org for a result. Thanks In reply to "Peter Otten" who wrote the following: > input/ldompel...@casema.nl wrote: > > > In reply to "Peter Otten" who wrote the following: > > > > > input/ldompel...@casema.nl wrote: > > > > > > > > choices = raw_input("letter s to stop:") > > > > > > > > Oh no, this is not what I want. Now it is waiting for input when its go > > > > further with the script. Because I have an while True: so I want that > > > > the script go's continue only when I press a key then it must stop the > > > > script. > > > > > > Solutions to that problem are OS-dependent. For Unix terminals > > > > > > https://docs.python.org/2/faq/ > > > library.html#how-do-i-get-a-single-keypress-at-a-time > > > > > > shows one way which I used to write the contextmanager below: > > > > > > $ cat capture_key.py > > > import termios, fcntl, sys, os > > > > > > from contextlib import contextmanager > > > > > > @contextmanager > > > def nonblocking(stdin=None): > > > if stdin is None: > > > stdin = sys.stdin > > > > > > fd = sys.stdin.fileno() > > > > > > oldterm = termios.tcgetattr(fd) > > > newattr = termios.tcgetattr(fd) > > > newattr[3] = newattr[3] & ~termios.ICANON & ~termios.ECHO > > > termios.tcsetattr(fd, termios.TCSANOW, newattr) > > > > > > oldflags = fcntl.fcntl(fd, fcntl.F_GETFL) > > Thanks for the reply. Is there no easy way to do so in python ? > > If you are asking for a ready-made function in the standard library, I don't > know one and I don't think there is one (there are recipes that work on top > of curses though). > > > I am using the raspberry pi with Wheezy and for the robot the GoPiGo which > > is connected on the raspberry pi. The GoPiGo board has his own code like: > > fwd()="forward" bwd()="backward" right()="right" left="left" and so on. I > > am just a dummie with python. > > The code in capture_key.py may look a bit scary, but just as I took it > without bothering the details you can take the resulting module without > caring about the code in it. Alternatively you can search > > https://pypi.python.org > > for a solution that you prefer. -- --------------------------------- --- -- - Posted with NewsLeecher v7.0 Beta 2 Web @ http://www.newsleecher.com/?usenet ------------------- ----- ---- -- - -- https://mail.python.org/mailman/listinfo/python-list