Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Cross Platform Getch() In Python

DZone's Guide to

Cross Platform Getch() In Python

·
Free Resource
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.
Topics:

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}