Skip to content

Fix text injection for non-US keyboard layouts - #12

Open
softwarewhale wants to merge 1 commit into
cjams:mainfrom
softwarewhale:fix/layout-agnostic-text-injection
Open

Fix text injection for non-US keyboard layouts#12
softwarewhale wants to merge 1 commit into
cjams:mainfrom
softwarewhale:fix/layout-agnostic-text-injection

Conversation

@softwarewhale

Copy link
Copy Markdown
Contributor

I use a German QWERTZ keyboard and noticed that transcribed text was coming out garbled - Y and Z were swapped, among other issues. Turns out ydotool type sends raw keycodes assuming US QWERTY, so on any other layout the characters get misinterpreted.

What this PR does

Instead of relying solely on ydotool, this adds native text injection that respects the system keyboard layout:

  • X11: Uses XTest extension via ctypes (XKeysymToKeycode + XTestFakeKeyEvent)
  • Wayland: Uses wtype if installed
  • Fallback: Still uses ydotool if neither is available

The backend is selected automatically based on the display server.

Backend priority

Display Server Primary Fallback
X11 XTest (libX11/libXtst) ydotool
Wayland wtype ydotool

Notes

  • No new Python dependencies
  • X11 libraries are already present on X11 systems
  • Existing ydotool setups continue to work

Testing

  • X11 with German (QWERTZ) layout
  • ⚠️ Wayland with wtype: Would appreciate help testing on Wayland systems to make sure the fallback chain works
  • Fallback to ydotool

❗️Disclaimer: I used AI to generate the code because neither python nor Linux display server specifics are my domain. If you don't want to merge it because of that, I can understand. I just wanted to share what I came up with to not gatekeep this fix. ❗️

ydotool sends keycodes assuming US QWERTY, which breaks on other
layouts (German QWERTZ swaps Y/Z, for example).

Added native injection that respects the active layout:
- X11: XTest extension via ctypes
- Wayland: wtype (if installed)
- Falls back to ydotool otherwise
@cjams

cjams commented Apr 21, 2026

Copy link
Copy Markdown
Owner

@softwarewhale have you had a chance to test on wayland?

@lovehumans

Copy link
Copy Markdown

What's the status here @cjams @softwarewhale ?
Are you guys still interested in this project or are you using something else?

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants