mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-04-26 03:59:08 +00:00
better getch() functions, fixed windows version (fixes #207)
This commit is contained in:
parent
c0d2af557c
commit
dd052d07b0
@ -51,19 +51,14 @@ if sys.version_info.major < 3:
|
|||||||
SCREENSHOT = False
|
SCREENSHOT = False
|
||||||
|
|
||||||
|
|
||||||
def getch():
|
# make a getch function
|
||||||
try:
|
try:
|
||||||
import termios
|
import termios
|
||||||
except ImportError:
|
import sys, tty
|
||||||
# Non-POSIX. Return msvcrt's (Windows') getch.
|
|
||||||
import msvcrt
|
|
||||||
return msvcrt.getch()
|
|
||||||
|
|
||||||
# POSIX system. Create and return a getch that manipulates the tty.
|
# POSIX system. Create and return a getch that manipulates the tty.
|
||||||
import sys
|
# On Windows, termios will fail to import.
|
||||||
import tty
|
|
||||||
|
|
||||||
def _getch():
|
def getch():
|
||||||
fd = sys.stdin.fileno()
|
fd = sys.stdin.fileno()
|
||||||
old_settings = termios.tcgetattr(fd)
|
old_settings = termios.tcgetattr(fd)
|
||||||
try:
|
try:
|
||||||
@ -73,7 +68,19 @@ def getch():
|
|||||||
termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
|
termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
|
||||||
return ch
|
return ch
|
||||||
|
|
||||||
return _getch()
|
except ImportError:
|
||||||
|
# Windows system.
|
||||||
|
# Use msvcrt's getch function.
|
||||||
|
import msvcrt
|
||||||
|
|
||||||
|
def getch():
|
||||||
|
while True:
|
||||||
|
key = msvcrt.getch()
|
||||||
|
if key in (0x00, 0xe0):
|
||||||
|
# skip special keys: read the scancode and repeat
|
||||||
|
msvcrt.getch()
|
||||||
|
continue
|
||||||
|
return key.decode('latin1')
|
||||||
|
|
||||||
|
|
||||||
def get_buttonrequest_value(code):
|
def get_buttonrequest_value(code):
|
||||||
|
Loading…
Reference in New Issue
Block a user