Command

Enum Command 

Source
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),
};

Fields

§text: String
§delay: Duration
§

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),
};

Fields

§delay: Duration

Trait Implementations§

Source§

impl Clone for Command

Source§

fn clone(&self) -> Command

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Command

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert 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>

Convert 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)

Convert &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)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.