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
impl Context
sourcepub fn new() -> Result<Self, GenericError<PlatformError>>
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
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
impl FallibleContext for Context
type PlatformError = PlatformError
source§impl KeyboardContext for Context
impl KeyboardContext for Context
source§impl MouseContext for Context
impl MouseContext for Context
source§fn mouse_move_rel(
&mut self,
dx: i32,
dy: i32
) -> Result<(), GenericError<PlatformError>>
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>>
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>>
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>>
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>>
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>>
fn mouse_click( &mut self, button: MouseButton ) -> Result<(), GenericError<PlatformError>>
Press and release a mouse button. Read more
source§impl ScreenContext for Context
impl ScreenContext for Context
source§fn cursor_location(&self) -> Result<(i32, i32), GenericError<PlatformError>>
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>>
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
impl UnicodeKeyboardContext for Context
source§fn unicode_char_down(
&mut self,
ch: char
) -> Result<(), GenericError<PlatformError>>
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>>
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>>
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>>
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§
impl RefUnwindSafe for Context
impl Send for Context
impl Sync for Context
impl Unpin for Context
impl UnwindSafe for Context
Blanket Implementations§
source§impl<C> AsciiKeyboardContext for Cwhere
C: KeyboardContext + FallibleContext,
impl<C> AsciiKeyboardContext for Cwhere
C: KeyboardContext + FallibleContext,
source§fn ascii_char_down(
&mut self,
ch: u8
) -> Result<(), GenericError<<C as FallibleContext>::PlatformError>>
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>>
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>>
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>>
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> 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
Mutably borrows from an owned value. Read more