pub struct Input(/* private fields */);Expand description
The frame’s keyboard/mouse/window input state.
A self-contained ECS resource — fetch it directly with Res<Input>,
no need to go through WindowResource<W> or name a concrete backend
type. Cheap to clone (an Arc internally), and every accessor locks
internally and hands back a plain value, so there’s no guard type to
hold onto: input.key_held(KeyCode::KeyW) just returns bool.
State is refreshed once per step, before systems run, so every accessor below reflects that step’s input.
Implementations§
Source§impl Input
impl Input
Sourcepub fn key_pressed(&self, key: KeyCode) -> bool
pub fn key_pressed(&self, key: KeyCode) -> bool
True the step a key goes from “not pressed” to “pressed”. Uses physical keys (layout-independent), so this is the one to reach for game controls rather than text entry.
Sourcepub fn key_released(&self, key: KeyCode) -> bool
pub fn key_released(&self, key: KeyCode) -> bool
True the step a key goes from “pressed” to “not pressed”.
Sourcepub fn held_shift(&self) -> bool
pub fn held_shift(&self) -> bool
True while either shift key is held.
Sourcepub fn held_control(&self) -> bool
pub fn held_control(&self) -> bool
True while either control key is held.
Sourcepub fn mouse_pressed(&self, button: MouseButton) -> bool
pub fn mouse_pressed(&self, button: MouseButton) -> bool
True the step a mouse button goes from “not pressed” to “pressed”.
Sourcepub fn mouse_released(&self, button: MouseButton) -> bool
pub fn mouse_released(&self, button: MouseButton) -> bool
True the step a mouse button goes from “pressed” to “not pressed”.
Sourcepub fn mouse_held(&self, button: MouseButton) -> bool
pub fn mouse_held(&self, button: MouseButton) -> bool
True for every step the mouse button remains pressed.
Sourcepub fn cursor(&self) -> Option<(f32, f32)>
pub fn cursor(&self) -> Option<(f32, f32)>
Cursor position in pixels, or None if the window isn’t focused (or
the cursor is off-window and no button is held).
Sourcepub fn cursor_diff(&self) -> (f32, f32)
pub fn cursor_diff(&self) -> (f32, f32)
Change in cursor position since the last step. (0.0, 0.0) under the
same conditions Input::cursor returns None.
Sourcepub fn mouse_diff(&self) -> (f32, f32)
pub fn mouse_diff(&self) -> (f32, f32)
Change in raw mouse motion since the last step — driven by device events rather than cursor position, so this is the one to reach for a captured-mouse first-person camera.
Sourcepub fn scroll_diff(&self) -> (f32, f32)
pub fn scroll_diff(&self) -> (f32, f32)
Scroll wheel delta (horizontal, vertical) since the last step.
Sourcepub fn close_requested(&self) -> bool
pub fn close_requested(&self) -> bool
True if the OS requested the window close this step (e.g. the title bar’s close button).
Sourcepub fn resolution(&self) -> Option<(u32, u32)>
pub fn resolution(&self) -> Option<(u32, u32)>
Current window resolution, or None before the first resize event.
Sourcepub fn dropped_file(&self) -> Option<PathBuf>
pub fn dropped_file(&self) -> Option<PathBuf>
Path of a file dropped onto the window this step, if any.
Sourcepub fn delta_time(&self) -> Option<Duration>
pub fn delta_time(&self) -> Option<Duration>
Time elapsed since the last step, or None while the first step is
still in progress.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Input
impl RefUnwindSafe for Input
impl Send for Input
impl Sync for Input
impl Unpin for Input
impl UnsafeUnpin for Input
impl UnwindSafe for Input
Blanket Implementations§
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> Component for T
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
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.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§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.Source§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.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more