Keyboard echo removed after using sshkeyboard in threaded code
On Raspberry Pi OS Bulleye (Debian 11) running Python 3.9.2 with sshkeyboard 2.3.1, the console ceases to echo after running a Python script invoking sshkeuboard in a threaded environment. Circumvention is to invoke
subprocess.run(["stty","echo"])
just before the script terminates.
The same effect is seen with Python 3.11.2 on Debian 11 running in Windows Subsystem for Linux. In this environment the response is variable - sometimes the echo returns, sometimes not. Sometimes it can be reactivated with
stty echo
entered 'blind' at the console and sometimes not. Sometimes it seems that the console can only be restored by closing the VM and restarting.
The following code behaves as described above: ` from sshkeyboard import listen_keyboard, stop_listening import sys import threading import subprocess
import time
TIMEOUT = 4
def press(key): print(f"'{key}' pressed") if key == 'z': print(f"key is <{key}>")
def process(): # until='z' stops listening on pressing the 'z' key listen_keyboard( on_press=press, until="z", ) print("'z' key pressed")
def main(): t = threading.Thread(target=process) t.daemon = True start = time.time() t.start() print(f"Waiting {TIMEOUT} seconds for background thread to finish.") t.join(TIMEOUT) if t.is_alive(): print("z key not pressed - timed out.") else: wait_time = time.time() - start print(f"z key pressed after {wait_time} seconds - within timeout of {TIMEOUT} seconds!")
# line below needed as sshkeyboard appears to disable console echo
#subprocess.run(["stty", "echo"])
return 0
if name == "main": main()
` Uncomment the "subprocess run" line for the circumvention.
sshkeyboard is a very useful piece of code so it would be good if this issue could be resolved, either by code change or documentation update.
Thanks