rs_uinput_kb
A high-performance Python module written in Rust (via PyO3) for simulating hardware-level keystrokes on Linux. By interfacing directly with /dev/uinput, this library creates a virtual USB keyboard, making it virtually undetectable by software-level input hooks.
It features built-in humanization (randomized typing delays) and a powerful macro syntax for executing complex keystroke combinations, modifier holds, and special characters all from a single string.
Features
- Hardware-Level Emulation: Bypasses X11/Wayland entirely. Types directly at the kernel level.
- Humanized Typing: Jittered delays between characters, randomized key-press dwell times, and varied shift-key hesitations.
- Inline Macro Syntax: Trigger special keys (
{enter},{backspace}) and modifier holds ({ctrl down}c{ctrl up}) directly within your text strings. - Blazing Fast: Core logic written in safe Rust.
Prerequisites
- Linux OS (Requires
/dev/uinputsupport) - Python 3.7+
- Rust & Cargo (for building)
- Root/Sudo Access (or configure
udevrules so your user can write to/dev/uinput)
Installation & Building
This project uses maturin to build the Rust code into a Python module.
- Install
maturinin your Python environment:
pip install maturin
- Build and install the module directly into your current virtual environment:
maturin develop --release
Usage Guide
Important: Because this script accesses /dev/uinput, you will likely need to run your Python script with sudo (e.g., sudo python main.py), unless you have set up specific user permissions for uinput.
Basic Humanized Typing
By default, the function adds slight, randomized delays to mimic a real human typing.
import rs_uinput_kb
# Types a simple string with natural human-like delays
rs_uinput_kb.type_text("Hello, world! I am typing like a human.")
Instant / Machine-Speed Typing
If you want the text to appear instantaneously, set all delay parameters to 0.
import rs_uinput_kb
rs_uinput_kb.type_text(
"This will appear instantly.",
min_char_delay=0.0,
max_char_delay=0.0,
min_dwell_time=0,
max_dwell_time=0,
min_shift_delay=0,
max_shift_delay=0,
startup_delay_ms=200 # Only wait 200ms for OS recognition
)
Advanced: Macros & Special Keys
The module supports an inline macro syntax using curly braces {}. This allows you to mix normal typing with special commands seamlessly.
import rs_uinput_kb
# 1. Tapping Special Keys
# Types "User", presses Tab, types "Password", presses Enter
rs_uinput_kb.type_text("User{tab}Password{enter}")
# 2. Deleting Text
# Types a typo, then uses backspace to correct it
rs_uinput_kb.type_text("The wrong word{backspace}{backspace}{backspace}{backspace}right word.")
# 3. Holding Modifiers (e.g., Copy and Paste)
# Highlights all text, copies it, moves right, and pastes it
rs_uinput_kb.type_text("{ctrl down}a{ctrl up}{ctrl down}c{ctrl up}{right}{ctrl down}v{ctrl up}")
# 4. Escaping Brackets
# If you need to actually type a curly bracket, use double brackets
rs_uinput_kb.type_text("def my_function() {{ return True; }}")
Supported Special Keys:
backspace, enter, tab, esc, space, up, down, left, right, shift, ctrl, alt, meta (or win, cmd), insert, delete, home, end, pageup, pagedown, capslock, f1 through f12.
API Reference
rs_uinput_kb.type_text(text, kwargs)
| Parameter | Type | Default | Description |
|---|---|---|---|
text |
str |
Required | The string of characters and {macros} to type. |
min_char_delay |
float |
0.05 |
Minimum wait time (in seconds) between pressing subsequent keys. |
max_char_delay |
float |
0.1 |
Maximum wait time (in seconds) between pressing subsequent keys. |
min_dwell_time |
int |
20 |
Minimum time (in milliseconds) a key is physically held down before release. |
max_dwell_time |
int |
60 |
Maximum time (in milliseconds) a key is physically held down before release. |
min_shift_delay |
int |
10 |
Minimum hesitation (in ms) before and after pressing the shift key for capital letters. |
max_shift_delay |
int |
30 |
Maximum hesitation (in ms) before and after pressing the shift key for capital letters. |
startup_delay_ms |
int |
500 |
Time (in ms) the script waits after creating the virtual /dev/uinput device before it starts typing. Note: If this is too low, the OS might miss the first few keystrokes. |
Troubleshooting
RuntimeError: Permission denied (os error 13)Your user does not have permission to read/write/dev/uinput. Run your Python script withsudoor add audevrule for theuinputgroup.- The first few characters are missing
The Linux kernel takes a fraction of a second to recognize a newly plugged-in (or virtual) USB device. Increase the
startup_delay_ms(e.g., to800or1000).
Metadata
Release files for rs-uinput-kb 2.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| rs_uinput_kb-2.1.1.tar.gz | 11.6 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| rs_uinput_kb-2.1.1-cp311-cp311-manylinux_2_34_x86_64.whl | CPython 3.11 | CPython 3.11 | Linux glibc 2.34+ x86-64 | Details |
Total release size: 243.0 kB
Release files / rs_uinput_kb-2.1.1.tar.gz
| Download URL | rs_uinput_kb-2.1.1.tar.gz |
|---|---|
| Size | 11.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
378bdd914976ed1005ddc59de91b0bdab9868ff735f793657e028481c7426f0e
|
|
BLAKE2b-256 checksum How to use checksums |
c1e4fd8c1c349ddedb268e340a89099ab29854d6139bd041f00e7762ab41654b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.14.0
|
Release files / rs_uinput_kb-2.1.1-cp311-cp311-manylinux_2_34_x86_64.whl
| Download URL | rs_uinput_kb-2.1.1-cp311-cp311-manylinux_2_34_x86_64.whl |
|---|---|
| Size | 231.3 kB |
| Tags | CPython 3.11 Linux glibc 2.34+ x86-64 |
|
SHA-256 checksum How to use checksums |
a20b74c16340dfee23453560010dfb976825a7ebde1311f97e3353fdd4769188
|
|
BLAKE2b-256 checksum How to use checksums |
b09ef46c7bed8d10d75f33a9356b9c42cda61a706c78668d3b4dd7590eb2744e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.14.0
|
Security for rs-uinput-kb 2.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.