DZone 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

Snippets has posted 5883 posts at DZone. View Full User Profile

Cross Platform Getch() In Python

  • submit to reddit
        For Unix, it uses sys, tty, termios modules.
import sys, tty, termios
fd = sys.stdin.fileno()
old_settings = termios.tcgetattr(fd)
ch =
For Windows, it uses msvcrt module.
import msvcrt
ch = msvcrt.getch()
See more details and OSX code in this <a href=>recipe</a> by Danny Yoo.