enigo
enigo copied to clipboard
On Linux text with Emoji fails
Describe the bug When using the text function with an emoji in it, everything prints correctly until the emoji appears, at which point execution stops, and the error message Invalid multi-byte sequence encountered is printed.
To Reproduce Steps to reproduce the behavior:
Use the text function with a string that includes an emoji. Observe that all text before the emoji is printed, but the process stops at the emoji. The error message "Invalid multi-byte sequence encountered" is displayed.
Expected behavior The full text, including the emoji, should be printed without interruption.
Environment (please complete the following information):
OS: Ubuntu 22.04 (Docker container)
The issue occurs consistently across different Linux distributions when using X11. It seems to be related to handling multi-byte Unicode sequences.
When I add this to the Docker container, the error stops, but so far emojis are still not working:
# Install locale packages and set locale
RUN apt-get update && apt-get install -y \
locales \
&& rm -rf /var/lib/apt/lists/* \
&& localedef -i en_US -c -f UTF-8 -A /usr/share/locale/locale.alias en_US.UTF-8
# Set locale environment variables
ENV LANG=en_US.UTF-8 \
LANGUAGE=en_US:en \
LC_ALL=en_US.UTF-8
Note: I'm using Xvfb with Xvfb :99 -screen 0 1600x1200x24 > /dev/null 2>&1 &
Thank you for the report. I'll try to have a look at it. It might take some time though. I am currently focusing on the Wayland code so I can add it to the default features.
Since you didn't mention any features, I assume you are using enigo with the default features? Enigo then uses the xdotools function to simulate the input
Yes, it's default usage. To be fair I'm not getting any other tool do work neither xdotools nor pyautogui or anything. At this point I'm assuming it might be an issue with Xvfb. Maybe I could also try Wayland instead.
By the way I created a node library with bindings to enigo-rs: https://github.com/karugamo/node-enigo Enigo has been super useful
Can you please try again with the feature x11rb?
When I run the keyboard example, the heart gets successfully entered. Unfortunately there are other issues when activating the The default feature is still the recommended one (hence its the default) but I wanted to change to x11rb to get rid of the runtime dependency. Testing it with the x11rb feature would help to find out if it is possible to simulate emojis with xvfb.x11rb feature though. For example the capital H does not get entered.
I know, I usually look at peoples profiles to see what they use enigo for :-) I am happy you found it useful and am glad you are creating bindings for it. Are you trying to run enigo in a docker container in order to test your bindings? Running proper integration tests is still an ongoing issue. Let me know if you run tests in the CI for your bindings, maybe I can copy some code to improve the upstream tests
I just remembered that the integration tests use Xvfb as well. They also test if emoji can get entered: https://github.com/enigo-rs/enigo/blob/4e051fa8d00df43ed347b448bf31d830a47274b6/tests/integration_browser.rs#L14 Since they pass for x11rb and xdo, I am pretty sure it's your docker container that lacks dependencies or something like that. Does it have a font that supports emoji?
Thank you for looking into it. Yeah, first the issue was that there wasn't emoji support. But then adding an emoji font also didn't fix it. It just removed the error message but the emojis weren't inserted. But good to know that it works for you with xvfb, I think it's somehow related to the docker image then. I already tried 2 different ones but it never worked. I will try again, once I have time to look into it.
Did you find the time to try again?