enigo
enigo copied to clipboard
Non-ascii characters not working on certain applications
Describe the bug Trying to simulate typing the string "hello world ❤️" in a text input field of firefox types only "hello world ". Similar results with other non-ascii characters, for example "¯\_(ツ)_/¯" results in "\_()_/". I also tested this keepassxc and it also fails. In other applications like chromium / alacritty / telegram-desktop the string is printed correctly.
To Reproduce
use enigo::{
Enigo,
MouseControllable,
KeyboardControllable,
};
fn main() {
let mut enigo = Enigo::new();
// Make the following line aim the cursor at a text input field
enigo.mouse_move_to(0, 0);
enigo.mouse_click(enigo::MouseButton::Left);
enigo.key_sequence("hello world ❤️");
}
Expected behavior "hello world ❤️" should be printed in the text input field.
"hello world " is printed instead.
Environment (please complete the following information):
- OS: Archlinux
- Rust:
rustc 1.43.0-nightly (d3c79346a 2020-02-29)
and alsorustc 1.41.1 (f3e1a954d 2020-02-24)
- Library Version: enigo 0.0.13
Additional context Might have something to do with #36 ?
Firefox version 73.0
From keepassxc
KeePassXC - Version 2.5.3 Revision: f8c962b
Qt 5.14.1
Do you have posted a comment recently? I got a notification but cannot see any new comment here? I have looked into this a little bit and i can reproduce this. It seems like Firefox does need some more time than other applications to recognize Non-ascii characters. Here is the modified example that is running on my System (Archlinux) (the thread::sleep(Duration::from_secs(1));
s are not necessary i just used them for convenience)
use enigo::{
Enigo,
MouseControllable,
KeyboardControllable,
};
use std::thread;
use std::time::Duration;
fn main() {
let mut enigo = Enigo::new();
// Make the following line aim the cursor at a text input field
enigo.mouse_move_relative(0, 0);
thread::sleep(Duration::from_secs(1));
enigo.mouse_click(enigo::MouseButton::Left);
thread::sleep(Duration::from_secs(1));
enigo.set_delay(400000);
enigo.key_sequence("hello world ❤️");
}
Yeah I posted a comment and deleted it because it was wrong. It didn't occur to me that github sends an email for comments and it would seem weird. Sorry about the confusion.
I added the delay as you suggest in my programme. And while this does make the problem better, it doesn't make it go away. What I mean is that, at least on my machine, with the delay it works some of the time, while some other times it still misses some non-ascii character. I had to try a few times to observe this.
No worries. I think this is just an unfortunate trait of Xorg that we have to live with :/ ... we tried many implementations to get this working reliably but couldn't really figure it out and just used xdo
in the end. Their code is similar to ours that we have started with but was a little bit more reliable. But in the end this is really just a "hack". I really don't know a better way to do this.
Regarding the "hack", with the key mapping. There is some documentation about it in Chapter 5. Keyboards on the following page: https://web.archive.org/web/20231005143214/https://x.org/releases/X11R7.7/doc/xproto/x11protocol.html
However it contradicts the actual behavior :-)