xkb-type
Layout-aware text injection for Linux — types correct characters regardless of the user's active keyboard layout.
Problem
Linux has no "type this text at the cursor" API. Every tool that injects text (wtype, ydotool, xdotool) sends fixed keycodes, which produce wrong characters when the user has a non-US keyboard layout. German users get "z" and "y" swapped; French users get "a" and "q" swapped; Russian users get complete gibberish.
Solution
xkb-type uses xkbcommon to read the active XKB keyboard layout, builds a reverse mapping from every Unicode character to the physical key + modifiers needed to produce it, then injects the correct keystrokes via a Linux uinput virtual keyboard.
Characters not found in the keymap (emoji, rare symbols) are pasted via clipboard (Ctrl+V).
Usage
use ;
use Duration;
// Auto-detect layout and clipboard backend.
let mut kb = new?;
kb.type_text?;
kb.backspace?;
kb.send_combo?;
To force a specific XKB layout (skips compositor probe):
use Keyboard;
use Duration;
let mut kb = with_layout?;
kb.type_text?;
To inject your own keymap and clipboard backend:
use ;
use Duration;
let layout = detect;
let keymap = from_layout?;
let mut kb = with_components?;
To pause or stop between keys, type through the KeyInjector trait. Its type_text asks a gate before every key with the byte offset of the next character; the gate may block, and ControlFlow::Break stops before that character:
use ControlFlow;
use Duration;
use ;
let mut kb: = Boxnew;
let text = "hello world";
let mut gate = ;
if let StoppedAt = kb.type_text?
Requirements
- Linux
- Write access to
/dev/uinput(user ininputgroup or udev rule) libxkbcommon(installed by default on most Linux desktops)wl-clipboardfor Wayland clipboard operations
Installation
cargo add xkb-type
License
MIT