cross-posted from: https://lemmy.world/post/27385536
I have a rather large Python script that I use as basically a replacement for autohotkey. It uses pynput for keyboard and mouse control - and at least on Windows, it works exactly how I expect.
I recently started dual-booting with Linux and have been trying to get the script to work here as well. It does work but with mixed results - in particular, I found that pynput has bizarrely wrong output for special characters, in a way that's both consistent and inconsistent.
The simplest possible case I found that reproduces the error is this script:
import time from pynput import keyboard # Sleep statement is just to give time to move the mouse cursor to a text input field time.sleep(2) my_kb = keyboard.Controller() text = '๐' # Eggplant emoji my_kb.type(text) time.sleep(1) text = '๐ฅ๐๐ค๐ฅ' # blackboard bold test my_kb.type(text) time.sleep(1) text = '๐ญ๐๐ฌ๐ญ' # bold test my_kb.type(text)
When I run that script right now, it produces the output "๐๐ฅ๐ฅ๐ค๐ฅ๐ญ๐ญ๐ฌ๐ญ". And if I run it again, it'll produce the same output. And if I change the eggplant emoji to something else, like the regular character 'A', it will still produce the same output (specifically "A๐ฅ๐ฅ๐ค๐ฅ๐ญ๐ญ๐ฌ๐ญ"). But... If I log out and log back in, then the output changes to something else that's still wrong, but differently. For example, when I changed the eggplant to a regular 'A', then relogged, the output became "A๐ฅ๐๐๐ฅ๐ญ๐๐๐ญ". And then that wrong output will keep being the same wrong output until I log out and back in again. If the test strings don't change, then the incorrect outputs don't change on relog - but if they do, then they do.
In the larger script, errors seemed to chain together somehow - like if I produced an eggplant emoji, then tried to write blackboard bold test, I would get "๐๐๐ค๐". This is despite verifying just before running the pynput.keyboard.Controller.type function that what it was about to type was correct. The issue also happens if I type it character-by-character with press and release functions.
I am very new to Linux. I'm on Linux Mint. I'm running this in a python3 venv that just has pynput and two other external libraries installed. ChatGPT thinks the issue might be related to X11. The issue does not occur at all on Windows, using the exact same code. On Linux there seems to be no issues with typing regular text, just special characters.