Skip to main content

InputHandler

Struct InputHandler 

Source
pub struct InputHandler<T>
where T: BindingTypes,
{ pub bindings: Bindings<T>, /* private fields */ }
Expand description

This struct holds state information about input devices.

For example, if a key is pressed on the keyboard, this struct will record that the key is pressed until it is released again.

Fields§

§bindings: Bindings<T>

Maps inputs to actions and axes.

Implementations§

Source§

impl<T> InputHandler<T>
where T: BindingTypes,

Source

pub fn new() -> Self

Creates a new input handler.

Source

pub fn send_event( &mut self, event: &Event, event_handler: &mut EventChannel<InputEvent<T>>, hidpi: f32, )

Updates the input handler with a new engine event.

The Amethyst game engine will automatically call this if the InputHandler is attached to the world as a resource.

Source

pub fn send_controller_event( &mut self, event: &ControllerEvent, event_handler: &mut EventChannel<InputEvent<T>>, )

Updates the input handler with a new controller event.

Called internally from SdlEventsSystem when using sdl_controller feature. You should invoke it in your system if you provide your own controller input implementation.

Source

pub fn send_frame_begin(&mut self)

This function is to be called whenever a frame begins. It resets some input values.

The InputSystem will call this automatically. If you’re using that system, you don’t need to call this function.

Source

pub fn keys_that_are_down(&self) -> impl Iterator<Item = VirtualKeyCode> + '_

Returns an iterator over all keys that are down.

Source

pub fn key_is_down(&self, key: VirtualKeyCode) -> bool

Checks if a key is down.

Source

pub fn mouse_buttons_that_are_down(&self) -> impl Iterator<Item = &MouseButton>

Returns an iterator over all pressed mouse buttons

Source

pub fn mouse_button_is_down(&self, mouse_button: MouseButton) -> bool

Checks if a mouse button is down.

Source

pub fn mouse_wheel_value(&self, horizontal: bool) -> f32

If the mouse wheel was scrolled this frame this function will return the direction it was scrolled.

If “horizontal” is true this will return the horizontal mouse value. You almost always want the vertical mouse value.

Source

pub fn scan_codes_that_are_down(&self) -> impl Iterator<Item = u32> + '_

Returns an iterator over all pressed scan codes

Source

pub fn scan_code_is_down(&self, scan_code: u32) -> bool

Checks if the key corresponding to a scan code is down.

Source

pub fn controller_buttons_that_are_down( &self, ) -> impl Iterator<Item = &(u32, ControllerButton)> + '_

Returns an iterator over all pressed controller buttons on all controllers.

Source

pub fn controller_button_is_down( &self, controller_id: u32, controller_button: ControllerButton, ) -> bool

Checks if a controller button is down on specific controller.

Source

pub fn connected_controllers(&self) -> impl Iterator<Item = u32> + '_

List controller ids of all currently connected controllers. IDs are assigned sequentially in the order of connection starting from 0, always taking the lowest next free number.

Source

pub fn is_controller_connected(&self, controller_id: u32) -> bool

Returns true if a controller with the given id is connected.

Source

pub fn mouse_position(&self) -> Option<(f32, f32)>

Gets the current mouse position.

this method can return None, either if no mouse is connected, or if no mouse events have been recorded

Source

pub fn buttons_that_are_down(&self) -> impl Iterator<Item = Button> + '_

Returns an iterator over all buttons that are down.

Source

pub fn button_is_down(&self, button: Button) -> bool

Checks if a button is down.

Source

pub fn axis_value<A>(&self, id: &A) -> Option<f32>
where T::Axis: Borrow<A>, A: Hash + Eq + ?Sized,

Returns the value of an axis by the id, if the id doesn’t exist this returns None.

Source

pub fn action_is_down<A>(&self, action: &A) -> Option<bool>
where T::Action: Borrow<A>, A: Hash + Eq + ?Sized,

Returns true if any of the actions bindings is down.

If a binding represents a combination of buttons, all of them need to be down.

Trait Implementations§

Source§

impl<T> Debug for InputHandler<T>
where T: BindingTypes,

Source§

fn fmt(&self, __f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T> Default for InputHandler<T>
where T: BindingTypes,

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Any for T
where T: Any,

Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> SetParameter for T

Source§

fn set<T>(&mut self, value: T) -> <T as Parameter<Self>>::Result
where T: Parameter<Self>,

Sets value as a parameter of self.
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

unsafe fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<T> TryDefault for T
where T: Default,

Source§

fn try_default() -> Result<T, String>

Tries to create the default.
Source§

fn unwrap_default() -> Self

Calls try_default and panics on an error case.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> Event for T
where T: Send + Sync + 'static,

Source§

impl<T> Resource for T
where T: Any + Send + Sync,