Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Cross platform getch() in python (See related posts)

For Unix, it uses sys, tty, termios modules.
import sys, tty, termios
fd = sys.stdin.fileno()
old_settings = termios.tcgetattr(fd)
tty.setraw(sys.stdin.fileno())
ch = sys.stdin.read(1)

For Windows, it uses msvcrt module.
import msvcrt
ch = msvcrt.getch()

See more details and OSX code in this recipe by Danny Yoo.

You need to create an account or log in to post comments to this site.


Click here to browse all 4861 code snippets

Related Posts