Skip to content

Repository files navigation

RiskyTextExpander

A simple text expander for Wayland. Monitors keyboard input and expands short text snippets into longer text or executes key commands.

Why "risky"? It's effectively a keylogger that auto-types without context awareness.

Features

  • Replace typed text, quickly by using wl-paste
  • Send commands as part of the replacement
  • Type keys, do not use wl-paste
  • Auto detect keyboard

Setup

Prerequisites

  • ydotoold: if the user is a part of the "input" group, you should be okay.
  • wl-copy for clipboard operations
  • Python 3 with venv, plus a C compiler and kernel headers — evdev is built from source (Arch: base-devel + linux-api-headers, Debian: build-essential + python3-dev).

Configuration

Config files are stored in ~/.config/risky-text-expander/
Examples will automatically copy on first run of start.sh

Text Expansions (config): Note: Backtick is protected, and must not be used for anything else.

zurl: https://github.com/emmertex/RiskyTextExpander
zbye: Kind Regards, Andrew Frahn
zhz: ❤️

Text Expansion with Commands: Note: Backtick is protected, and must not be used for anything else.

midbold: Middle `bold`word`bold` bold.
zgoodbye: Kind Regards,`enter`Andrew Frahn`enter``bold`Emmertex`bold``send`
ztyped: `t``y``p``e``d` pasted.`enter`

Key Commands (commands.config): Note: commands must be >2 characters

bold: ctrl+b
send: ctrl+enter
enter: enter

Usage

Start the service:

./rte.sh

rte.sh creates .venv/ on first run, updates the packages in it on every start, then hands over to start.sh.

Flag / variable Effect
--no-update (or RTE_SKIP_UPDATE=1) Skip the package update — faster, and works offline
--recreate Delete and rebuild the venv
--list-devices Print every input device and why it was or was not treated as a keyboard
RTE_VENV=/path Put the venv somewhere other than .venv/

start.sh still works on its own if you manage the environment yourself.

Picking the right keyboard

Every device that classifies as a full keyboard is monitored, so multiple keyboards work at once. Devices created by keystroke injectors (ydotoold and friends) are always skipped — otherwise the expander would read back its own output. If detection gets it wrong, start with:

./rte.sh --list-devices

then narrow it down:

Variable Effect
RISKY_INPUT_DEVICES Comma-separated device paths to use instead of auto-detection. /dev/input/by-id/… symlinks are recommended — they survive reboots and re-plugging
RISKY_KEYBOARD_INCLUDE Comma-separated name substrings; only matching keyboards are monitored
RISKY_KEYBOARD_EXCLUDE Comma-separated name substrings to skip
RISKY_DEBUG=1 Verbose [RiskyDBG] tracing on stderr, including every accept/reject decision

How it Works

  • Monitors the last 10 lowercase characters typed
  • On match: deletes the typed text and replaces it
  • Text segments are pasted via clipboard
  • Key commands (in backticks) execute keyboard shortcuts

Your clipboard

Pasting is how expansions get typed, so the clipboard is used as scratch space — but it is saved before the expansion and put back afterwards, byte for byte. Images and other binary content survive too. Only one MIME type can be handed back (a limitation of wl-copy), so a clipboard offering several flavours comes back as the richest single one: images first, then plain text.

Variable Effect
RISKY_RESTORE_CLIPBOARD=0 Don't save/restore — leave the expansion text on the clipboard
RISKY_CLIPBOARD_RESTORE_DELAY Seconds to wait after pasting before restoring (default 0.25). Raise it if a slow application occasionally pastes your old clipboard instead of the expansion
RISKY_CLIPBOARD_MAX_BYTES Don't snapshot clipboards larger than this (default 8 MiB)

Example

Here are a few examples based on the sample configurations.

Simple Expansion:

  • Typing: zurl
  • Result: https://github.com/emmertex/RiskyTextExpander is pasted.

Expansion with Commands:

  • Typing: midbold
  • Result: "Middle word bold." is typed out. This assumes bold is mapped to ctrl+b which toggles bold formatting in your text editor.

Complex Expansion with Commands:

  • Typing: zgoodbye
  • Result:
Kind Regards,
Andrew Frahn
**Emmertex**

This text is output, and then ctrl+enter is pressed, which would send the message in many chat and email applications.

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages