pub trait InputApi {
    // Required methods
    fn key(&self, key: &str) -> bool;
    fn key_pressed(&mut self, key: &str) -> bool;
    fn keys_pressed(&self) -> Keys<'_> ;
    fn key_released(&mut self, key: &str) -> bool;
    fn keys_released(&self) -> Keys<'_> ;
    fn text(&self) -> String;
    fn mouse_button(&self, num: usize) -> bool;
    fn mouse_button_pressed(&mut self, num: usize) -> bool;
    fn mouse_button_released(&mut self, num: usize) -> bool;
    fn mouse_pos(&self) -> (f32, f32);
    fn close_requested(&self) -> bool;
}
Expand description

Provides information about user input. Possible values for the key scancode parameter can be found in unrust/uni-app’s translate_scan_code function. Warning, there are some slight variations from one OS to another, for example the Command, F13, F14, F15 keys only exist on Mac.

State functions like InputApi::key, InputApi::mouse_button and InputApi::mouse_pos always work. On another hand, pressed/released event functions should be called only in the update function.

Required Methods§

source

fn key(&self, key: &str) -> bool

return the current status of a key (true if pressed)

source

fn key_pressed(&mut self, key: &str) -> bool

return true if a key was pressed since last update.

source

fn keys_pressed(&self) -> Keys<'_>

return an iterator over all the keys that were pressed since last update.

source

fn key_released(&mut self, key: &str) -> bool

return true if a key was released since last update.

source

fn keys_released(&self) -> Keys<'_>

return an iterator over all the keys that were released since last update.

source

fn text(&self) -> String

characters typed since last update

source

fn mouse_button(&self, num: usize) -> bool

return the current status of a mouse button (true if pressed)

source

fn mouse_button_pressed(&mut self, num: usize) -> bool

return true if a mouse button was pressed since last update.

source

fn mouse_button_released(&mut self, num: usize) -> bool

return true if a mouse button was released since last update.

source

fn mouse_pos(&self) -> (f32, f32)

return the current mouse position in console cells coordinates (float value to have subcell precision)

source

fn close_requested(&self) -> bool

Whether the window close button was clicked

Implementors§