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.