Single key press

Steven D'Aprano steve+comp.lang.python at pearwood.info
Tue Dec 6 03:48:39 EST 2011


On Tue, 06 Dec 2011 10:19:55 +0430, Sergi Pasoev wrote:

> Hi.
> 
> I wonder if it is realistic to get a single key press in Python without
> ncurses or
> any similar library. In single key press I mean something like j and k
> in Gnu less
> program, you press the key and and it is captured by the script without
> need to press enter afterwards


Coincidentally, I was working on that exact function last night, so you 
inspired me to put it up on the Python cookbook. This version should work 
on any POSIX system such as Linux, as well as Windows. I don't know if it 
will work on Macintosh.

http://code.activestate.com/recipes/577977-get-single-keypress/



-- 
Steven



More information about the Python-list mailing list