This repository has been archived on 2025-05-08. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
Snake/getkey.py

23 lines
519 B
Python
Executable file

import sys
import termios
import tty
def getkey() -> str:
def gk() -> str:
fd: int = sys.stdin.fileno()
old_settings = termios.tcgetattr(fd)
try:
tty.setraw(sys.stdin.fileno())
ch: str = sys.stdin.read(1)
finally:
termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
return ch
out: str = gk()
if out == "\033":
o: str = gk()
if o == "[":
return out + o + gk()
return out + o
return out