import threading import winsound from pynput import keyboard IS_START = False def get_start(): return IS_START def listener_keyword(): def on_press(key): global IS_START try: if key.char == "=": IS_START = not IS_START print(f"IS_START: {IS_START}") if IS_START: winsound.Beep(800, 200) else: winsound.Beep(400, 200) except AttributeError: pass with keyboard.Listener(on_press=on_press) as listener: listener.join() threading.Thread(target=listener_keyword, daemon=True).start()