From 787274836a9f0a4f59711bf2c9891236d622c0de Mon Sep 17 00:00:00 2001 From: ElectraBytes04 Date: Sun, 1 Sep 2024 20:33:06 -0400 Subject: [PATCH] input_handler.py 1.0 --- include/input_handler.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 include/input_handler.py diff --git a/include/input_handler.py b/include/input_handler.py new file mode 100644 index 0000000..c66ed3a --- /dev/null +++ b/include/input_handler.py @@ -0,0 +1,26 @@ +import sys + +if sys.platform == "win32": + import msvcrt + getch = msvcrt.getch +else: + import tty, termios + def getch(): + fd = sys.stdin.fileno() + old = termios.tcgetattr(fd) + try: + tty.setraw(fd) + return sys.stdin.read(1) + finally: + termios.tcsetattr(fd, termios.TCSADRAIN, old) + +print("Start typing (press Enter to finish):") + +def input_loop(gameinput_func): + while True: + char = getch() + # if char == 'my super secret escape code': + # do_some_launcher_magic(char) + # else: + gameinput_func(char) + print(f"{char}")