import threading 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}") except AttributeError: pass with keyboard.Listener(on_press=on_press) as listener: listener.join() threading.Thread(target=listener_keyword).start()