Enum winit_input_map::Input
source · pub enum Input {
Key(PhysicalKey),
Mouse(MouseButton),
}
Variants§
Key(PhysicalKey)
Mouse(MouseButton)
Implementations§
source§impl Input
impl Input
sourcepub const fn keycode(key: KeyCode) -> Self
pub const fn keycode(key: KeyCode) -> Self
Examples found in repository?
examples/example.rs (line 17)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
fn main() {
enum Actions {
Debug,
Left,
Right,
Click,
}
impl Into<usize> for Actions {
fn into(self) -> usize {
self as usize
}
}
use winit_input_map::{Input, InputMap};
use Actions::*;
let mut input = InputMap::new([
(vec![Input::keycode(KeyCode::Space)], Debug),
(
vec![
Input::keycode(KeyCode::ArrowLeft),
Input::keycode(KeyCode::KeyA),
],
Left,
),
(
vec![
Input::keycode(KeyCode::ArrowRight),
Input::keycode(KeyCode::KeyD),
],
Right,
),
(vec![Input::Mouse(MouseButton::Left)], Click),
]);
use winit::{event::*, keyboard::KeyCode, window::Window};
let event_loop = winit::event_loop::EventLoop::new().unwrap();
event_loop.set_control_flow(winit::event_loop::ControlFlow::Poll);
let _window = Window::new(&event_loop).unwrap();
event_loop
.run(|event, target| {
input.update(&event);
match &event {
Event::WindowEvent {
event: WindowEvent::CloseRequested,
..
} => target.exit(),
Event::AboutToWait => {
if input.pressed(Debug) {
println!("pressed {:?}", input.binds(Debug))
}
if input.pressing(Right) || input.pressing(Left) {
println!("axis: {}", input.axis(Right, Left))
}
if input.mouse_move != (0.0, 0.0) {
println!(
"mouse moved: {:?} and is now at {:?}",
input.mouse_move, input.mouse_pos
)
}
if input.released(Click) {
println!("released {:?}", input.binds(Click))
}
std::thread::sleep(std::time::Duration::from_millis(100));
//since init is required to be called once before update, we put it at the end before it loops.
input.init(); //could use `init_hide_mouse()` instead. good for camera controls
}
_ => (),
}
})
.unwrap();
}
Trait Implementations§
source§impl PartialEq for Input
impl PartialEq for Input
impl Copy for Input
impl Eq for Input
impl StructuralPartialEq for Input
Auto Trait Implementations§
impl Freeze for Input
impl RefUnwindSafe for Input
impl Send for Input
impl Sync for Input
impl Unpin 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
Mutably borrows from an owned value. Read more
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>
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
.source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Convert
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)
Convert
&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)
Convert
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.