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.
- Transcripts leak into clipboard history and the Microsoft cloud clipboard. Writing
CF_UNICODETEXTalone opts into both. Seeclipboard::set_text_private. - Held modifiers corrupt the synthesized chord. In push-to-talk a modifier is held by
construction when injection fires. See
modifiers::sanitize. - Injection into elevated windows fails silently. UIPI blocks it and reports nothing
through
GetLastErroror the return value, so text vanishes. SeeTarget::accepts_injection. - 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.
- Clipboard
Only Reason - 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
texttotarget.