pub enum Command {
Text {
text: String,
delay: Duration,
},
ModPress(Modifier),
ModRelease(Modifier),
KeyPress(String),
KeyRelease(String),
Sleep(Duration),
StdinText {
delay: Duration,
},
}Expand description
Internal command representation after parsing command-line arguments. Each command represents a single action to be executed in sequence.
§Examples
use wrtype::Command;
use std::time::Duration;
// Type "Hello" with 100ms delay between characters
let text_cmd = Command::Text {
text: "Hello".to_string(),
delay: Duration::from_millis(100),
};
// Create Ctrl+C shortcut sequence
let ctrl_c = vec![
Command::ModPress(wrtype::Modifier::Ctrl),
Command::KeyPress("c".to_string()),
Command::KeyRelease("c".to_string()),
Command::ModRelease(wrtype::Modifier::Ctrl),
];
// Press and hold Escape key
let hold_escape = Command::KeyPress("Escape".to_string());
// Add timing delay in sequence
let pause = Command::Sleep(Duration::from_millis(500));Variants§
Text
Type a string of text with specified delay between characters
§Example
// Type "Hello, World!" with 50ms between each character
let cmd = Command::Text {
text: "Hello, World!".to_string(),
delay: Duration::from_millis(50),
};ModPress(Modifier)
Press a modifier key (adds to current modifier state)
Multiple modifiers can be pressed simultaneously by calling this multiple times.
The modifier remains pressed until explicitly released with ModRelease.
§Example
// Press Ctrl (remains held)
let press_ctrl = Command::ModPress(Modifier::Ctrl);
// Press Shift while Ctrl is still held
let press_shift = Command::ModPress(Modifier::Shift);ModRelease(Modifier)
Release a modifier key (removes from current modifier state)
Should be paired with corresponding ModPress commands to avoid
releasing modifiers that weren’t pressed by wrtype.
§Example
// Complete Ctrl+Shift+T sequence
let sequence = vec![
Command::ModPress(Modifier::Ctrl),
Command::ModPress(Modifier::Shift),
Command::KeyPress("t".to_string()),
Command::KeyRelease("t".to_string()),
Command::ModRelease(Modifier::Shift),
Command::ModRelease(Modifier::Ctrl),
];KeyPress(String)
Press a named key (key stays pressed until released)
Uses XKB key names. The key remains pressed until a corresponding
KeyRelease command is executed.
§Example
// Press and hold the Return key
let hold_return = Command::KeyPress("Return".to_string());
// Press arrow keys
let press_left = Command::KeyPress("Left".to_string());
let press_f1 = Command::KeyPress("F1".to_string());KeyRelease(String)
Release a named key
Should be paired with corresponding KeyPress commands.
§Example
// Complete key press sequence
let key_tap = vec![
Command::KeyPress("space".to_string()),
Command::KeyRelease("space".to_string()),
];Sleep(Duration)
Sleep for specified duration (for timing control)
Useful for creating precise timing in key sequences or waiting for applications to respond.
§Example
// Wait 1 second
let pause = Command::Sleep(Duration::from_secs(1));
// Short pause between rapid keystrokes
let micro_pause = Command::Sleep(Duration::from_millis(50));StdinText
Read and type text from stdin with specified delay
Processes UTF-8 text from standard input and types each character with the specified delay between them.
§Example
// Read from stdin with 10ms delay per character
let stdin_cmd = Command::StdinText {
delay: Duration::from_millis(10),
};Trait Implementations§
Auto Trait Implementations§
impl Freeze for Command
impl RefUnwindSafe for Command
impl Send for Command
impl Sync for Command
impl Unpin for Command
impl UnwindSafe for Command
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.