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

In MacOS, enigo.text doesn't insert text correctly when holding the Command or Control key #297

Closed
xitanggg opened this issue Jun 23, 2024 · 2 comments · Fixed by #326
Closed

Comments

@xitanggg
Copy link

Describe the bug
Thanks for creating this helpful library. I observe a bug in MacOS, where enigo.text doesn't insert text correctly if user is holding the Command or Control key

To Reproduce
Below is a simple code snip to insert Hello world! after 3 seconds

let mut enigo = Enigo::new(&Settings::default()).unwrap();
thread::sleep(time::Duration::from_millis(3000));
enigo.text("Hello world!").unwrap();

Expected behavior
Happy path: Run the script, observe Hello world! is printed correctly.
Non-happy path: Run the script, hold Command (or Control) key, observe Hello world! isn't printed.

Environment (please complete the following information):

  • OS: macOS
  • Rust: rustc 1.79.0
  • Library Version: latest

Additional context
I was able to figure out a workaround to this issue, which is to release the key before calling enigo.text

let mut enigo = Enigo::new(&Settings::default()).unwrap();
thread::sleep(time::Duration::from_millis(3000));
enigo.key(Key::Meta, Release).unwrap();
enigo.text("Hello world!").unwrap();

This bug affects application built on top of enigo that uses global keyboard shortcut containing Command / Control to trigger text, in which case text insert would fail

@pentamassiv
Copy link
Collaborator

Thank you for letting me know. I'll have to investigate how to solve this properly. It might take some time

pentamassiv added a commit to pentamassiv/enigo that referenced this issue Sep 10, 2024
Previously the state of the physical keyboard effected the result of the simulated input. If the Command key was held on the physical keyboard, the text() function no longer worked. By default the two are now independent, but this behavior can be changed with the Settings struct (`independent_of_keyboard_state`).
Fixes enigo-rs#297
@pentamassiv
Copy link
Collaborator

Sorry it took a while, but I found a clean solution to the problem. By default the state of the physical keyboard no longer has an effect on the simulated input.
I created a PR for it: #326 and will likely publish a new release soon.

Feel free to remove your workarounds :-)

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

Successfully merging a pull request may close this issue.

2 participants