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

Key::Unicode on MacOS does not behave the same way as on Windows & Linux #307

Open
UE2020 opened this issue Aug 12, 2024 · 3 comments
Open

Comments

@UE2020
Copy link

UE2020 commented Aug 12, 2024

Describe the bug
On Windows & Linux, calling enigo.key(Key::Shift, Press) followed by enigo.key(Key::Unicode("1"), Press) produces an exclamation mark in a textarea. On MacOS, a number one is produced. This is reproducible only with numbers (shift + any letter produces the expected uppercase letter).

Expected behavior
Holding shift and a number should produce the special character associated with that combination regardless of the OS.

Environment

  • OS: Tested on Windows 11, Arch Linux on X.org, and MacOS ventura 13.2.1 (22D68) running on Mac M2 Air
  • Rust: rustc 1.79.0 (129f3b996 2024-06-10)
  • Library Version: 0.2.1
@pentamassiv
Copy link
Collaborator

If you want to enter text, you should always use the text() method. Entering individual keys is slower and -at least for now - can lead to inconsistent or unexpected behavior. I need to improve it

@UE2020
Copy link
Author

UE2020 commented Aug 18, 2024

The text() method isn't a solution for me because I'm using enigo in a remote desktop app, where keys should be held for as long as the client on the other end holds them. Right now I think get_layoutdependent_keycode is at fault.

@UE2020
Copy link
Author

UE2020 commented Aug 30, 2024

@pentamassiv I fixed the issue in my project by replacing the get_layoutdependent_keycode function with a hardcoded match statement from this C function. Obviously this means that only ascii characters can be emulated with Key::Unicode, but that doesn't matter for my usecase. You can see the changes I made at my fork of enigo.

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

No branches or pull requests

2 participants