Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stop_listening() and exceptions do not stop listening #6

Open
ghost opened this issue Nov 15, 2022 · 0 comments
Open

stop_listening() and exceptions do not stop listening #6

ghost opened this issue Nov 15, 2022 · 0 comments

Comments

@ghost
Copy link

ghost commented Nov 15, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

0 participants