sshkeyboard
sshkeyboard copied to clipboard
stop_listening() and exceptions do not stop listening
from sshkeyboard import listen_keyboard, stop_listening
class StopException(Exception):
pass
def keypress(key):
if key == 's':
# stop_listening()
raise StopException()
print(key)
while True:
print('listening from now')
try:
listen_keyboard(on_press=keypress, until='enter', sequential=True, delay_second_char=0, delay_other_chars=0)
except StopException:
# stop_listening()
print('listening requested to be stopped')
As soon as s is pressed for the first time and the loop reiterates, I am getting an AssertionError: Only one listener allowed at a time. It doesn't matter which of or even if both of the stop_listening() calls are uncommented.
In the first place, I would expect an exception to stop the listening anyway.
But I am even manually requesting stop_listening(), yet listen_keyboard cannot be called again because somehow it thinks that it is already listening.
AssertionError: Only one listener allowed at a time