Enum tfc::Command[][src]

pub enum Command {
    Delay(u32),
    KeyDown(Key),
    KeyUp(Key),
    KeyClick(Key),
    MouseMoveRel(i32i32),
    MouseMoveAbs(i32i32),
    MouseScroll(i32i32),
    MouseDown(MouseButton),
    MouseUp(MouseButton),
    MouseClick(MouseButton),
    AsciiCharDown(u8),
    AsciiCharUp(u8),
    AsciiChar(u8),
    AsciiString(Vec<u8>),
    UnicodeCharDown(char),
    UnicodeCharUp(char),
    UnicodeChar(char),
    UnicodeString(String),
}

A future invocation of a method on a Context.

Commands can be executed by calling execute. Each variant corresponds to a method on one of the traits.

Variants

Delay(u32)

Creates a delay for a number of milliseconds

KeyDown(Key)

Corresponds to key_down

KeyUp(Key)

Corresponds to key_up

KeyClick(Key)

Corresponds to key_click

MouseMoveRel(i32i32)

Corresponds to mouse_move_rel

MouseMoveAbs(i32i32)

Corresponds to mouse_move_abs

MouseScroll(i32i32)

Corresponds to mouse_scroll

MouseDown(MouseButton)

Corresponds to mouse_down

MouseUp(MouseButton)

Corresponds to mouse_up

MouseClick(MouseButton)

Corresponds to mouse_click

AsciiCharDown(u8)

Corresponds to ascii_char_down

AsciiCharUp(u8)

Corresponds to ascii_char_up

AsciiChar(u8)

Corresponds to ascii_char

AsciiString(Vec<u8>)

Corresponds to ascii_string

UnicodeCharDown(char)

Corresponds to unicode_char_down

UnicodeCharUp(char)

Corresponds to unicode_char_up

UnicodeChar(char)

Corresponds to unicode_char

UnicodeString(String)

Corresponds to unicode_string

Implementations

impl Command[src]

pub fn from_bytes(buf: &[u8]) -> Result<(Command, usize), CommandBytesError>[src]

Construct a Command from a sequence of bytes.

The first byte in the buffer must be a CommandCode. This identifies the command and its arguments. Following the command identifier is a sequence of bytes that encode the arguments of the command. Key and MouseButton are single bytes. For integer arguments (used for moving the mouse and scrolling), signed 16-bit big-endian integers are used.

Since a negative delay is impossible, the millisecond parameter for the Delay command is unsigned.

An ASCII character is a single byte. An ASCII string is a length followed by a sequence of bytes. The length is a unsigned 16-bit big-endian integer.

A Unicode character (or more specifically, a Unicode scalar value) is 32-bits. A Unicode string is similar to an ASCII string in that it has a length followed by a sequence of bytes, however the sequence of bytes are a UTF-8 encoded string.

The function returns the command and the number of bytes that were read from the buffer.

Examples

use tfc::{Command, CommandCode, Key};

let bytes = &[
    CommandCode::MouseMoveRel as u8, 255, 214, 0, 64,
    CommandCode::KeyClick as u8, Key::K as u8,
    CommandCode::UnicodeString as u8, 0, 4, 0xF0, 0x9F, 0xA4, 0xAA,
];

let (command, len) = Command::from_bytes(bytes).unwrap();
assert_eq!(len, 5);
assert_eq!(command, Command::MouseMoveRel(-42, 64));

let bytes = &bytes[len..];
let (command, len) = Command::from_bytes(bytes).unwrap();
assert_eq!(len, 2);
assert_eq!(command, Command::KeyClick(Key::K));

let bytes = &bytes[len..];
let (command, len) = Command::from_bytes(bytes).unwrap();
assert_eq!(len, 7);
assert_eq!(command, Command::UnicodeString("🤪".to_owned()));

pub fn execute<C>(
    &self,
    ctx: &mut C
) -> Result<(), GenericError<C::PlatformError>> where
    C: FallibleContext + KeyboardContext + MouseContext + AsciiKeyboardContext
[src]

Execute a Command by calling the corresponding method on one of the traits.

Trait Implementations

impl Debug for Command[src]

impl Eq for Command[src]

impl PartialEq<Command> for Command[src]

impl StructuralEq for Command[src]

impl StructuralPartialEq for Command[src]

Auto Trait Implementations

impl RefUnwindSafe for Command

impl Send for Command

impl Sync for Command

impl Unpin for Command

impl UnwindSafe for Command

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.