pub struct Input { /* private fields */ }
Expand description
Manages player input bindings and allows reading key/button presses and axes
Implementations
sourceimpl Input
impl Input
sourcepub fn add_action(&mut self, name: &str)
pub fn add_action(&mut self, name: &str)
Creates a new input action with the given name.
sourcepub fn add_bind(&mut self, name: &str, key: &str)
pub fn add_bind(&mut self, name: &str, key: &str)
Adds an input binding to the given action. If the action doesn’t exist, it will be created. See the module-level documentation for a list of key names.
sourcepub fn clear_binds(&mut self, name: &str)
pub fn clear_binds(&mut self, name: &str)
Removes all the bindings from the given action.
sourcepub fn deadzone(&self, composite_axis: &str) -> Option<f64>
pub fn deadzone(&self, composite_axis: &str) -> Option<f64>
Gets the deadzone for the given composite axis. See the module-level documentation for a list of composite axis names.
sourcepub fn set_deadzone(&mut self, composite_axis: &str, deadzone: f64) -> bool
pub fn set_deadzone(&mut self, composite_axis: &str, deadzone: f64) -> bool
Sets the deadzone for the given composite axis. See the module-level documentation for a list of composite axis names.
sourcepub fn down_once(&self, name: &str) -> bool
pub fn down_once(&self, name: &str) -> bool
Returns true if the given action was pressed this frame
sourcepub fn up_once(&self, name: &str) -> bool
pub fn up_once(&self, name: &str) -> bool
Returns true if the given action was released this frame
sourcepub fn held(&self, name: &str) -> bool
pub fn held(&self, name: &str) -> bool
Returns true if the given action is currently being held
sourcepub fn time_held(&self, name: &str) -> u64
pub fn time_held(&self, name: &str) -> u64
Returns the number of frames that the given action was held for, or 0 if it is not held.
sourcepub fn time_released(&self, name: &str) -> u64
pub fn time_released(&self, name: &str) -> u64
Returns the number of frames that the given action was released for, or 0 if it is not released.
sourcepub fn axis(&self, name: &str) -> f64
pub fn axis(&self, name: &str) -> f64
Returns the current value between 0.0 and 1.0 for the axis associated with the given action. This will only return the value of an individual positive/negative component. If you want a combined positive/negative range, see Input::paired_axis().
sourcepub fn paired_axis(&self, name_neg: &str, name_pos: &str) -> f64
pub fn paired_axis(&self, name_neg: &str, name_pos: &str) -> f64
Returns the current value between -1.0 and 1.0 for the negative and positive part associated with the negative and positive actions, respectively.
sourcepub fn paired_axis_2d(
&self,
name_left: &str,
name_right: &str,
name_up: &str,
name_down: &str
) -> (f64, f64)
pub fn paired_axis_2d(
&self,
name_left: &str,
name_right: &str,
name_up: &str,
name_down: &str
) -> (f64, f64)
Returns the current values between -1.0 and 1.0 for the 2D axis given four actions representing each cardinal direction. The distance is capped at a Euclidean distance value of 1.0 to avoid overly large diagonal values for sticks with square gates.
sourcepub fn angle_and_distance(
&self,
name_left: &str,
name_right: &str,
name_up: &str,
name_down: &str
) -> (f64, f64)
pub fn angle_and_distance(
&self,
name_left: &str,
name_right: &str,
name_up: &str,
name_down: &str
) -> (f64, f64)
Returns the current angle and distance for the 2D axis given four actions representing each cardinal direction. The distance is capped at a Euclidean distance value of 1.0 to avoid overly large diagonal values for sticks with square gates.
sourcepub fn four_way_direction(
&self,
name_left: &str,
name_right: &str,
name_up: &str,
name_down: &str
) -> Option<InputDirection4>
pub fn four_way_direction(
&self,
name_left: &str,
name_right: &str,
name_up: &str,
name_down: &str
) -> Option<InputDirection4>
Returns the currently pressed four-way direction given four actions representing each cardinal direction. If no direction is held, or the 2D axis is too close to a diagonal, returns None.
sourcepub fn eight_way_direction(
&self,
name_left: &str,
name_right: &str,
name_up: &str,
name_down: &str
) -> Option<InputDirection8>
pub fn eight_way_direction(
&self,
name_left: &str,
name_right: &str,
name_up: &str,
name_down: &str
) -> Option<InputDirection8>
Returns the currently pressed eight-way direction given four actions representing each cardinal direction. If no direction is held, returns None.
sourcepub fn cursor_position(&self) -> (f64, f64)
pub fn cursor_position(&self) -> (f64, f64)
Returns the current mouse cursor position in game screen coordinates. These are not raw window coordinates. For example, if you have a game at 320x224 and the window is scaled to 640x448, then placing your cursor in the bottom right of the window’s client area will return a position close to (320, 224).
sourcepub fn cursor_motion(&self) -> (f64, f64)
pub fn cursor_motion(&self) -> (f64, f64)
Returns the amount that the mouse moved this logic frame. This is not guaranteed to match 1-to-1 with the values returned from Input::cursor_position(). With the cursor unlocked, the motion may not match with the reported position if the window is a different size from the game’s base size. With the cursor locked, the motion is taken from raw mouse input if available, so it most likely will not match with the reported position even if the values are scaled up or down.
sourcepub fn cursor_visible(&self) -> bool
pub fn cursor_visible(&self) -> bool
Returns true if the mouse cursor is displayed when it is over the game window.
sourcepub fn set_cursor_visible(&mut self, visible: bool)
pub fn set_cursor_visible(&mut self, visible: bool)
Sets whether the mouse cursor is displayed when it is over the game window.
sourcepub fn cursor_locked(&self) -> bool
pub fn cursor_locked(&self) -> bool
Returns true if the mouse cursor is currently locked.
sourcepub fn set_cursor_locked(&mut self, locked: bool)
pub fn set_cursor_locked(&mut self, locked: bool)
Sets whether the mouse cursor is locked. When locked, the cursor will be trapped inside the window, and Input::cursor_motion() will report raw mouse motion if available.
Auto Trait Implementations
impl RefUnwindSafe for Input
impl !Send for Input
impl !Sync for Input
impl Unpin for Input
impl UnwindSafe for Input
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Downcast for T where
T: Any,
impl<T> Downcast for T where
T: Any,
sourcefn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>
fn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>
Convert 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
sourcefn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
Convert Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
. Read more
sourcefn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert &Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s. Read more
sourcefn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert &mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s. Read more