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

Incorrect work with delay in write function #582

Open
DanilXO opened this issue Dec 29, 2022 · 1 comment
Open

Incorrect work with delay in write function #582

DanilXO opened this issue Dec 29, 2022 · 1 comment

Comments

@DanilXO
Copy link

DanilXO commented Dec 29, 2022

Hello! I was working on my joke project using this library and found a strange bug. The delay parameter in the write function does not work correctly on Mac OS. We don't wait every delay time before every letter input, but wait a delay before every word input.

This is very easy to fix. Like this:

def write(text, delay=0, restore_state_after=True, exact=None):
    """
    ...
    """
    if exact is None:
        exact = _platform.system() == 'Windows'

    state = stash_state()
    
    # Window's typing of unicode characters is quite efficient and should be preferred.
    if exact:
        for letter in text:
            if letter in '\n\b':
                send(letter)
            else:
                _os_keyboard.type_unicode(letter)
            if delay: _time.sleep(delay)
    else:
        for letter in text:
            try:
                entries = _os_keyboard.map_name(normalize_name(letter))
                scan_code, modifiers = next(iter(entries))
            except (KeyError, ValueError):
                _os_keyboard.type_unicode(letter)
                # todo: We should add "if delay: _time.sleep(delay)" here.
                continue
            
            for modifier in modifiers:
                press(modifier)

            _os_keyboard.press(scan_code)
            _os_keyboard.release(scan_code)

            for modifier in modifiers:
                release(modifier)

            if delay:
                _time.sleep(delay)

    if restore_state_after:
        restore_modifiers(state)

Should I create a PR for this?

@DanilXO
Copy link
Author

DanilXO commented Dec 29, 2022

I have created PR: #583

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

1 participant