Skip to content

Instantly share code, notes, and snippets.

@MOOOWOOO
Created December 6, 2021 02:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MOOOWOOO/7f595d3bdbc43d4263eb7f5cf99b6dbf to your computer and use it in GitHub Desktop.
Save MOOOWOOO/7f595d3bdbc43d4263eb7f5cf99b6dbf to your computer and use it in GitHub Desktop.
get_char_without_enter
# coding: utf-8
__author__ = 'Jux.Liu'
import termios
import sys, tty
def getch():
def _getch():
fd = sys.stdin.fileno()
old_settings = termios.tcgetattr(fd)
try:
tty.setraw(fd)
ch = sys.stdin.read(1)
finally:
termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
return ch
return _getch()
a = ""
print("input 'z' to exit")
while a != "z":
a = getch()
print("your input:\t", a)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment