Created
December 6, 2021 02:58
-
-
Save MOOOWOOO/7f595d3bdbc43d4263eb7f5cf99b6dbf to your computer and use it in GitHub Desktop.
get_char_without_enter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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