Skip to main content

Crate win_text_inject

Crate win_text_inject 

Source
Expand description

Correct text injection into the focused Windows application.

Every open-source dictation tool surveyed in July 2026 delivers text the same way: save the clipboard, overwrite it, synthesize Ctrl+V, sleep(), restore. That approach has three defects that this crate exists to fix.

  1. Transcripts leak into clipboard history and the Microsoft cloud clipboard. Writing CF_UNICODETEXT alone opts into both. See clipboard::set_text_private.
  2. Held modifiers corrupt the synthesized chord. In push-to-talk a modifier is held by construction when injection fires. See modifiers::sanitize.
  3. Injection into elevated windows fails silently. UIPI blocks it and reports nothing through GetLastError or the return value, so text vanishes. See Target::accepts_injection.
  4. The clipboard restore races the target’s read. A target reads the clipboard whenever its message pump gets to the paste, so a timer-based restore can win and the target then reads the previous clipboard. Any fixed delay is a guess. See delayed.

§Example

// Capture at hotkey press, so focus changes during dictation cannot misdirect the text.
let target = win_text_inject::Target::foreground()?;

// ... record and transcribe ...

let outcome = win_text_inject::inject(&target, "hello world", Default::default())?;
if outcome.needs_manual_paste() {
    // Text is on the clipboard; tell the user to press Ctrl+V.
}

Re-exports§

pub use delayed::Offer;
pub use sendinput::type_text;
pub use sendinput::INJECT_TAG;

Modules§

clipboard
Clipboard writes that stay out of clipboard history, cloud sync, and third-party managers.
delayed
Delayed clipboard rendering: know exactly when the target read the clipboard.
modifiers
Release physically-held modifier keys before synthesizing input.
sendinput
Synthesized keyboard input, tagged so the sender’s own low-level hook can ignore it.

Structs§

Options
Tunables. Defaults are deliberately conservative.
Target
The window that will receive injected text, captured as a snapshot.

Enums§

Chord
Key combination used to trigger a paste in the target application.
ClipboardOnlyReason
Why the text was left on the clipboard instead of being delivered.
Error
Failures that are worth distinguishing at the call site.
Integrity
Windows integrity levels, ordered. Comparison is what matters, not the raw RID.
Outcome
What actually happened, so the caller can tell the user the truth.
Strategy
How text should be delivered.

Functions§

inject
Deliver text to target.