keystroke check

Michele Simionato mis6 at pitt.edu
Thu Jul 31 12:00:10 EDT 2003


Wes Fraser <ugly_411 at yahoo.com> wrote in message news:<mailman.1059619004.15764.python-list at python.org>...
> Is there any way to check in a loop to see if at that
> given moment in the program, a key on the key board is
> being pressed without actually stopping like raw_ipnut
> does?
> 
> Thanks!
> 
> Wes
> 
> __________________________________
> Do you Yahoo!?
> Yahoo! SiteBuilder - Free, easy-to-use web site design software
> http://sitebuilder.yahoo.com

On Unix/Linux you could use curses:

import curses

def wait4q(stdscr):
    stdscr.addstr("Press 'q' to exit\n")
    while True:
        if stdscr.getch()==ord('q'): break

if __name__=='__main__':
    curses.wrapper(wait4q)

However, curses could be overkill and it is not portable to Windows, AFAIK.
The curses how-to suggest the console module,
http://effbot.org/zone/console-index.htm
which runs on Windows only.
HTH,

      Michele




More information about the Python-list mailing list