Struct winit_input_helper::WinitInputHelper
source · pub struct WinitInputHelper { /* private fields */ }
Expand description
The main struct of the API.
Call update_from_vec
or update
once per main loop.
Then call any of the accessor methods.
Implementations§
source§impl WinitInputHelper
impl WinitInputHelper
pub fn new() -> WinitInputHelper
sourcepub fn update_from_vec(&mut self, events: Vec<Event>)
pub fn update_from_vec(&mut self, events: Vec<Event>)
Pass every event to this function.
WinitInputHelper::Update
is easier to use.
But this method is useful if you want to inspect the events yourself before giving them to WinitInputHelper
.
Ensure this method is only called once per application main loop.
Ensure every event since the last update_from_vec
call is included in the events
argument.
sourcepub fn update(&mut self, events_loop: &mut EventsLoop)
pub fn update(&mut self, events_loop: &mut EventsLoop)
Takes every event from the events_loop.
If you need to inspect the events yourself use WinitInputHelper::update_from_vec
.
Ensure this method is only called once per application main loop.
sourcepub fn key_pressed(&self, check_key_code: VirtualKeyCode) -> bool
pub fn key_pressed(&self, check_key_code: VirtualKeyCode) -> bool
Returns true when the specified keyboard key goes from “not pressed” to “pressed” Otherwise returns false
sourcepub fn mouse_pressed(&self, check_mouse_button: usize) -> bool
pub fn mouse_pressed(&self, check_mouse_button: usize) -> bool
Returns true when the specified mouse button goes from “not pressed” to “pressed” Otherwise returns false
Left => 0 Right => 1 Middle => 2 Other => 3..255
sourcepub fn key_released(&self, check_key_code: VirtualKeyCode) -> bool
pub fn key_released(&self, check_key_code: VirtualKeyCode) -> bool
Returns true when the specified keyboard key goes from “pressed” to “not pressed” Otherwise returns false
sourcepub fn mouse_released(&self, check_mouse_button: usize) -> bool
pub fn mouse_released(&self, check_mouse_button: usize) -> bool
Returns true when the specified mouse button goes from “pressed” to “not pressed” Otherwise returns false
Left => 0 Right => 1 Middle => 2 Other => 3..255
sourcepub fn key_held(&self, key_code: VirtualKeyCode) -> bool
pub fn key_held(&self, key_code: VirtualKeyCode) -> bool
Returns true while the specified keyboard key remains “pressed” Otherwise returns false
sourcepub fn mouse_held(&self, mouse_button: usize) -> bool
pub fn mouse_held(&self, mouse_button: usize) -> bool
Returns true while the specified mouse button remains “pressed” Otherwise returns false
Left => 0 Right => 1 Middle => 2 Other => 3..255
sourcepub fn held_shift(&self) -> bool
pub fn held_shift(&self) -> bool
Returns true while any shift key is held on the keyboard Otherwise returns false
sourcepub fn held_control(&self) -> bool
pub fn held_control(&self) -> bool
Returns true while any control key is held on the keyboard Otherwise returns false
sourcepub fn held_alt(&self) -> bool
pub fn held_alt(&self) -> bool
Returns true while any alt key is held on the keyboard Otherwise returns false
sourcepub fn scroll_diff(&self) -> f32
pub fn scroll_diff(&self) -> f32
Returns 0.0
if the mouse is outside of the window.
Otherwise returns the amount scrolled by the mouse in between the last two update*()
calls
sourcepub fn mouse(&self) -> Option<(f32, f32)>
pub fn mouse(&self) -> Option<(f32, f32)>
Returns None
when the mouse is outside of the window.
Otherwise returns the mouse coordinates in pixels
sourcepub fn game_mouse(&self, camera: Camera) -> Option<(f32, f32)>
pub fn game_mouse(&self, camera: Camera) -> Option<(f32, f32)>
Returns None
when the mouse is outside of the window.
Otherwise returns the mouse coordinates in the game world.
sourcepub fn mouse_diff(&self) -> (f32, f32)
pub fn mouse_diff(&self) -> (f32, f32)
Returns the difference in mouse coordinates between the last two update*()
calls
Returns (0.0, 0.0)
if the mouse is outside of the window.
sourcepub fn game_mouse_diff(&self, camera: Camera) -> (f32, f32)
pub fn game_mouse_diff(&self, camera: Camera) -> (f32, f32)
Returns the difference in mouse coordinates between the last two update*()
calls
Returns (0.0, 0.0)
if the mouse is outside of the window.
sourcepub fn resolution(&self) -> Option<(u32, u32)>
pub fn resolution(&self) -> Option<(u32, u32)>
Returns None
when the mouse is outside of the window.
Otherwise returns the resolution of the window.
sourcepub fn text(&self) -> Vec<TextChar>
pub fn text(&self) -> Vec<TextChar>
Returns the characters pressed since the last update*()
.
The earlier the character was pressed, the lower the index in the Vec.
sourcepub fn dropped_file(&self) -> Option<PathBuf>
pub fn dropped_file(&self) -> Option<PathBuf>
Returns the path to a file that has been drag-and-dropped onto the window.
sourcepub fn window_resized(&self) -> Option<LogicalSize>
pub fn window_resized(&self) -> Option<LogicalSize>
Returns the current window size if it was resized between the last two update*()
calls.
Otherwise returns None
Auto Trait Implementations§
impl RefUnwindSafe for WinitInputHelper
impl Send for WinitInputHelper
impl Sync for WinitInputHelper
impl Unpin for WinitInputHelper
impl UnwindSafe for WinitInputHelper
Blanket Implementations§
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>
fn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
. Read more§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
. Read more§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s. Read more§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s. Read more