[][src]Struct winconsole::input::InputContext

pub struct InputContext {
    pub repeat_enabled: bool,
    pub restore_on_drop: bool,
    // some fields omitted
}

Used to obtain input events.

Fields

repeat_enabled: bool

Should repeated events be sent?

restore_on_drop: bool

Should the context restore the original input mode when it is dropped?

Methods

impl InputContext[src]

pub fn flush(&mut self)[src]

Clears the context's input event queue.

Examples

let mut ctx = input::start().unwrap();
ctx.flush();

pub fn get(&mut self) -> WinResult<Vec<InputEvent>>[src]

Returns all of the input events which are currently in the queue.

Examples

let mut ctx = input::start().unwrap();
loop {
    let events = ctx.get().unwrap();
    for event in events {
        println!("{}", event);
    }
}

Errors

  • InvalidHandleError: Returned if an invalid handle to the console input is retrieved or used.
  • IoError: Returned if an OS error occurs.

pub fn get_filter(&self) -> InputFilter[src]

Returns the current input filter.

Examples

let mut ctx = input::start().unwrap();
let filter = ctx.get_filter();
println!("MouseDown events filtered? {}", filter.MouseDown);

pub fn peek(&mut self, max_length: u32) -> WinResult<Vec<InputEvent>>[src]

Reads data from the input queue without discarding it.

Arguments

  • max_length - The maximum amount of input events to return.

Examples

let mut ctx = input::start().unwrap();
let peeked = ctx.peek(5).unwrap();
println!("Peeked: {}", peeked.len());
for event in peeked.iter() {
    println!("{}", event);
}

Errors

  • InvalidHandleError: Returned if an invalid handle to the console output is retrieved or used.
  • IoError: Returned if an OS error occurs.

pub fn poll(&mut self) -> WinResult<InputEvent>[src]

Returns a single input event, or InputEvent::None if none are available.

Examples

let mut ctx = input::start().unwrap();
loop {
    let event = ctx.poll().unwrap();
    if event != InputEvent::None {
        println!("{}", event);
    }
}

Errors

  • InvalidHandleError: Returned if an invalid handle to the console output is retrieved or used.
  • IoError: Returned if an OS error occurs.

pub fn reset(&mut self)[src]

Resets the internal state of the context, clearing data about which keys and buttons are currently held along with the event queue.

Examples

let mut ctx = input::start().unwrap();
ctx.wait().unwrap();
ctx.reset();
let event = ctx.wait().unwrap();
println!("{}", event);

pub fn set_filter(&mut self, filter: InputFilter)[src]

Sets InputEvent types which should not be returned from methods.

Arguments

  • filter - The InputFilter to apply.

Examples

let mut ctx = input::start().unwrap();
let mut filter = InputFilter::new();
filter.MouseDown = true;
ctx.set_filter(filter);

pub fn simulate(&mut self, event: impl Into<InputEvent>)[src]

Adds an input event to the input queue.

Arguments

  • event - The InputEvent to add.

Examples

let mut ctx = input::start().unwrap();
let mut focus_event = FocusEvent::new();
focus_event.focused = true;
ctx.simulate(focus_event);

let event = ctx.wait().unwrap();
println!("{}", event);

pub fn wait(&mut self) -> WinResult<InputEvent>[src]

Waits until an input event is available and returns it.

Examples

let mut ctx = input::start().unwrap();
let event = ctx.wait().unwrap();
println!("{}", event);

Errors

  • InvalidHandleError: Returned if an invalid handle to the console output is retrieved or used.
  • IoError: Returned if an OS error occurs.

Trait Implementations

impl Drop for InputContext[src]

Auto Trait Implementations

impl Send for InputContext

impl Sync for InputContext

Blanket Implementations

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.

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

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

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