[Tutor] key detection

Steven D'Aprano steve at pearwood.info
Thu May 7 01:40:16 CEST 2015


On Tue, May 05, 2015 at 09:30:12PM -0700, Jim Mooney Py3.4.3winXP wrote:
> On 5 May 2015 at 18:32, Steven D'Aprano <steve at pearwood.info> wrote:
> 
> > https://code.activestate.com/recipes/577977-get-single-keypress/
> 
> 
> That only has a stub for Linux, 

Er, look again, more closely.

I happen to know the author very well *wink* and know that he run that 
specific code under Linux and it works fine. He's never tested it under 
Windows, so if it erases your hard drive don't blame him. Blame the 
authors of msvcrt.getch.

The general structure of the code goes:

try:
    import tty, termios
except ImportError:
    # handle Windows and other platforms without 
    # the tty and termios modules
else:
    # define Unix/Linux version of getch


> but I found one that does both. Although,
> alas, no IOS version:

If iOS supports tty and termios, it will just work.


> http://code.activestate.com/recipes/134892-getch-like-unbuffered-character-reading-from-stdin/

Ewww. Talk about unnecessary use of classes.

http://www.youtube.com/watch?v=o9pEzgHorH0


-- 
Steve


More information about the Tutor mailing list