Struct tfc::Context

source ·
pub struct Context;
Expand description

The main context used for generating events (Windows).

The most useful methods are on the traits.

Implementations§

source§

impl Context

source

pub fn new() -> Result<Self, GenericError<PlatformError>>

Examples found in repository?
examples/ascii.rs (line 14)
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
fn main() -> Result<(), Error> {
    let delay = Duration::from_millis(50);

    let mut ctx = Context::new()?;

    for c in b' '..=b'~' {
        thread::sleep(delay);
        ctx.unicode_char(c as char)?;
        ctx.ascii_char(b' ')?;
        ctx.ascii_char(c)?;
        ctx.ascii_char(b'\n')?;
    }

    Ok(())
}
More examples
Hide additional examples
examples/rotate-mouse.rs (line 10)
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
fn main() -> Result<(), Error> {
    let radius = 100.0;
    let steps = 200;
    let revolutions = 3;
    let delay = Duration::from_millis(10);

    let mut ctx = Context::new()?;
    let center = ctx.cursor_location()?;
    let center = (center.0 as f64 - radius, center.1 as f64);

    for step in 0..steps * revolutions {
        thread::sleep(delay);
        let angle = step as f64 * 2.0 * PI / steps as f64;
        let x = (center.0 + radius * angle.cos()).round() as i32;
        let y = (center.1 + radius * angle.sin()).round() as i32;
        ctx.mouse_move_abs(x, y)?;
    }

    Ok(())
}

Trait Implementations§

source§

impl FallibleContext for Context

§

type PlatformError = PlatformError

source§

impl KeyboardContext for Context

source§

fn key_down(&mut self, key: Key) -> Result<(), GenericError<PlatformError>>

Press down a key.
source§

fn key_up(&mut self, key: Key) -> Result<(), GenericError<PlatformError>>

Release a key.
source§

fn key_click(&mut self, key: Key) -> Result<(), GenericError<PlatformError>>

Press and release a key. Read more
source§

impl MouseContext for Context

source§

fn mouse_move_rel( &mut self, dx: i32, dy: i32 ) -> Result<(), GenericError<PlatformError>>

Move the mouse relative to its current location. Read more
source§

fn mouse_move_abs( &mut self, x: i32, y: i32 ) -> Result<(), GenericError<PlatformError>>

Move the mouse to an absolute location. Read more
source§

fn mouse_scroll( &mut self, dx: i32, dy: i32 ) -> Result<(), GenericError<PlatformError>>

Scroll the mouse horizontally and vertically in pixels. Read more
source§

fn mouse_down( &mut self, button: MouseButton ) -> Result<(), GenericError<PlatformError>>

Press down a mouse button.
source§

fn mouse_up( &mut self, button: MouseButton ) -> Result<(), GenericError<PlatformError>>

Release a mouse button.
source§

fn mouse_click( &mut self, button: MouseButton ) -> Result<(), GenericError<PlatformError>>

Press and release a mouse button. Read more
source§

impl ScreenContext for Context

source§

fn cursor_location(&self) -> Result<(i32, i32), GenericError<PlatformError>>

Get the location of the cursor in pixels. Read more
source§

fn screen_size(&self) -> Result<(i32, i32), GenericError<PlatformError>>

Get the size of the main screen in pixels. Read more
source§

impl UnicodeKeyboardContext for Context

source§

fn unicode_char_down( &mut self, ch: char ) -> Result<(), GenericError<PlatformError>>

Generate a key press event (possibly including modifiers) for a Unicode character. Read more
source§

fn unicode_char_up( &mut self, ch: char ) -> Result<(), GenericError<PlatformError>>

Generate a key release event (possibly including modifiers) for a Unicode character. Read more
source§

fn unicode_char(&mut self, ch: char) -> Result<(), GenericError<PlatformError>>

Generate a key press and release event along with the necessary modifiers to type a unicode character. Read more
source§

fn unicode_string(&mut self, s: &str) -> Result<(), GenericError<PlatformError>>

Generate key presses and releases such that a Unicode string is typed. 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<C> AsciiKeyboardContext for C

source§

fn ascii_char_down( &mut self, ch: u8 ) -> Result<(), GenericError<<C as FallibleContext>::PlatformError>>

Generate a key press event (possibly including shift) for an ASCII character. Read more
source§

fn ascii_char_up( &mut self, ch: u8 ) -> Result<(), GenericError<<C as FallibleContext>::PlatformError>>

Generate a key release event (possibly including shift) for an ASCII character. Read more
source§

fn ascii_char( &mut self, ch: u8 ) -> Result<(), GenericError<<C as FallibleContext>::PlatformError>>

Generate a key press and release event to type an ASCII character. Read more
source§

fn ascii_string( &mut self, s: &[u8] ) -> Result<(), GenericError<<C as FallibleContext>::PlatformError>>

Generate key presses and releases such that an ASCII string is typed. 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>,

§

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

§

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.