diff --git a/src/osc_sender.py b/src/osc_sender.py index 0d865c3..6d6d8fe 100644 --- a/src/osc_sender.py +++ b/src/osc_sender.py @@ -84,36 +84,32 @@ class OSCSender: print("No chords loaded!") return - import tty - import termios - import os + import select + import signal # Send and display first chord self.send_chord(self.current_index) self.display_chord(self.current_index) def get_key(): - """Get a single keypress. Returns None on error.""" - try: - fd = sys.stdin.fileno() - old_settings = termios.tcgetattr(fd) - try: - tty.setraw(sys.stdin.fileno()) - ch = sys.stdin.read(1) - return ch - finally: - termios.tcsetattr(fd, termios.TCSADRAIN, old_settings) - except (termios.error, OSError): - # Fallback for non-tty environments - return sys.stdin.read(1) if sys.stdin else None + """Get a keypress with timeout. Returns None if no key pressed.""" + if select.select([sys.stdin], [], [], 0.1)[0]: + return sys.stdin.read(1) + return None print("\nUse arrow keys to navigate. Press Ctrl+C to quit.") + # Handle SIGINT explicitly + def handle_sigint(signum, frame): + raise KeyboardInterrupt + + signal.signal(signal.SIGINT, handle_sigint) + try: while True: key = get_key() if key is None: - break + continue # Left arrow if key == "\x1b": # Escape sequence start