Struct Keyboard

Source
pub struct Keyboard<'a> { /* private fields */ }
Expand description

A struct for controlling a virtual keyboard.

It holds a reference to a Device which is used to send the keyboard commands.

Implementations§

Source§

impl<'a> Keyboard<'a>

Source

pub const fn new(device: &'a Device) -> Self

Creates a new Keyboard.

Source

pub fn press(&self, button: Key)

Presses a single keyboard button.

The button is held down until a release() or multi_press() with Key::NONE is called.

§Arguments
  • button - The Key to press.
Source

pub fn release(&self)

Releases all currently pressed keyboard buttons.

This effectively sends a “no keys pressed” command to the device.

Source

pub fn press_and_release(&self, button: Key, millis: u64)

Presses and releases a single keyboard button.

The button is pressed down, held for the specified duration, then released.

§Arguments
  • button - The Key to press and release.
  • millis - The duration in milliseconds to hold the button down before releasing it.
Source

pub fn multi_press( &self, button1: Key, button2: Key, button3: Key, button4: Key, button5: Key, button6: Key, )

Presses up to six keyboard buttons simultaneously.

This can be used for pressing modifier keys and other keys at the same time.

§Arguments
  • button1 - The first Key to press.
  • button2 - The second Key to press.
  • button3 - The third Key to press.
  • button4 - The fourth Key to press.
  • button5 - The fifth Key to press.
  • button6 - The sixth Key to press.
Source

pub fn type_string(&self, string: &str, millis: u64) -> Result<(), String>

Types a string by simulating individual key presses for each character.

§Arguments
  • string - The string to be typed.
  • millis - The duration in milliseconds to hold the button down before releasing it.
§Errors

This function will return an error if a character in the input string cannot be converted into a valid Key enum variant.

Auto Trait Implementations§

§

impl<'a> Freeze for Keyboard<'a>

§

impl<'a> RefUnwindSafe for Keyboard<'a>

§

impl<'a> !Send for Keyboard<'a>

§

impl<'a> !Sync for Keyboard<'a>

§

impl<'a> Unpin for Keyboard<'a>

§

impl<'a> UnwindSafe for Keyboard<'a>

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> 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, 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.