Struct winit_input_map::InputMap

source ·
pub struct InputMap<const BINDS: usize> {
    pub binds: [Vec<Input>; BINDS],
    pub pressing: [bool; BINDS],
    pub pressed: [bool; BINDS],
    pub released: [bool; BINDS],
    pub mouse_move: (f32, f32),
    pub mouse_pos: (f32, f32),
}
Expand description

input system. define actions and their key binds and then see if their pressing, pressed or released. get mouse position and how much its moved. you can use anythin that implements the Into<usize> trait as an action, but it’s recommended to use an action enum.

enum Actions{
    Debug,
    Left,
    Right,
    Click
}
impl Into<usize> for Actions{
    fn into(self) -> usize {
        self as usize
    }
}
use input::{InputMap, Input};
use Actions::*;

let mut input = Input::new([
    (vec![Input::keycode(KeyCode::Space)], Debug),
    (vec![Input::keycode(KeyCode::ArrowLeft), InputCode::keycode(KeyCode::KeyA)], Left),
    (vec![Input::keycode(KeyCode::ArrowRight), InputCode::keycode(KeyCode::KeyD)], Right),
    (vec![Input::Mouse(MouseButton::Left)], Click)
]);
     
use winit::{event::*, keyboard::KeyCode, window::WindowAttribures};
let event_loop = winit::event_loop::EventLoop::new().unwrap();
event_loop.set_control_flow(winit::event_loop::ControlFlow::Poll);
let _window = event_loop.create_window(WindowAttribures::default()).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 also use `init_hide_mouse()`
        }
        _ => ()
    }
}).unwrap();

Fields§

§binds: [Vec<Input>; BINDS]§pressing: [bool; BINDS]§pressed: [bool; BINDS]§released: [bool; BINDS]§mouse_move: (f32, f32)§mouse_pos: (f32, f32)

Implementations§

source§

impl<const BINDS: usize> InputMap<BINDS>

source

pub fn new(binds: [(Vec<Input>, impl Into<usize>); BINDS]) -> Self

create new input system. recommended to use an action enum which implements the Into<usize> trait for the second value.

enum Action{
    Forward,
    Back,
    Left,
    Right
}
impl Into<usize> for Action{
    fn into(self) -> usize{
        self as usize
    }
}

use Action::*;
use input::{Input, InputCode};
use winit::keyboard::KeyCode;
//doesnt have to be the same ordered as the enum.
let mut input = Input::new([
    (vec![Input::keycode(KeyCode::KeyW)], Forward),
    (vec![Input::keycode(KeyCode::KeyA)], Left),
    (vec![Input::keycode(KeyCode::KeyS)], Back),
    (vec![Input::keycode(KeyCode::KeyD)], Right)
]);
Examples found in repository?
examples/example.rs (lines 16-33)
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
74
75
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::WindowAttributes};
    let event_loop = winit::event_loop::EventLoop::new().unwrap();
    event_loop.set_control_flow(winit::event_loop::ControlFlow::Poll);
    let _window = event_loop
        .create_window(WindowAttributes::default())
        .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();
}
source

pub fn update(&mut self, event: &Event<()>)

updates the input using a winit event. requires input.init() to be used before being updated.

use winit::event::*;
use input::Input;

let mut event_loop = winit::event_loop::EventLoopBuilder::new().build().unwrap();
event_loop.set_control_flow(winit::event_loop::ControlFlow::Poll);

let mut input = Input::new([]);

event_loop.run(|event, target|{
    input.update(&event);
    match &event{
        Event::WindowEvent { event: WindowEvent::CloseRequested, .. } => target.exit(),
        Event::AboutToWait => input.init(), //could also use `init_hide_mouse()`
        _ => ()
    }
});
Examples found in repository?
examples/example.rs (line 44)
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
74
75
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::WindowAttributes};
    let event_loop = winit::event_loop::EventLoop::new().unwrap();
    event_loop.set_control_flow(winit::event_loop::ControlFlow::Poll);
    let _window = event_loop
        .create_window(WindowAttributes::default())
        .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();
}
source

pub fn init_hide_mouse(&mut self, window: &mut Window)

hides and centres mouse. usefull for camera controls, use instead of input.init() required to put input.init() before input.update()

use winit::{event::*, window::WindowAttribures};
use input::InputMap;

let mut event_loop = winit::event_loop::EventLoopBuilder::new().build().unwrap();
event_loop.set_control_flow(winit::event_loop::ControlFlow::Poll);
let mut window = event_loop.create_window(WindowAttribures::default());
let mut input = InputMap::new([]);

event_loop.run(|event, target|{
    input.update(&event);
    match &event{
        Event::WindowEvent { event: WindowEvent::CloseRequested, .. } => target.exit(),
        Event::AboutToWait => input.init_hide_mouse(&mut window),
        _ => ()
    }
});
source

pub fn init(&mut self)

initialise input. required to be called for mouse_move, pressed() and released() to work. required to put input.init() before input.update()

use winit::event::*;
use input::InputMap;

let mut event_loop = winit::event_loop::EventLoopBuilder::new().build().unwrap();
event_loop.set_control_flow(winit::event_loop::ControlFlow::Poll);

let mut input = InputMap::new([]);

event_loop.run(|event, target|{
    input.update(&event);
    match &event{
        Event::WindowEvent { event: WindowEvent::CloseRequested, .. } => target.exit(),
        Event::AboutToWait => input.init(),
        _ => ()
    }
});
Examples found in repository?
examples/example.rs (line 69)
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
74
75
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::WindowAttributes};
    let event_loop = winit::event_loop::EventLoop::new().unwrap();
    event_loop.set_control_flow(winit::event_loop::ControlFlow::Poll);
    let _window = event_loop
        .create_window(WindowAttributes::default())
        .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();
}
source

pub fn binds(&mut self, action: impl Into<usize>) -> &mut Vec<Input>

get binds of action. same as self.binds[action.into()]

Examples found in repository?
examples/example.rs (line 52)
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
74
75
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::WindowAttributes};
    let event_loop = winit::event_loop::EventLoop::new().unwrap();
    event_loop.set_control_flow(winit::event_loop::ControlFlow::Poll);
    let _window = event_loop
        .create_window(WindowAttributes::default())
        .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();
}
source

pub fn pressing(&self, action: impl Into<usize>) -> bool

checks if action is being pressed currently. same as self.pressing[action.into()]

Examples found in repository?
examples/example.rs (line 54)
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
74
75
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::WindowAttributes};
    let event_loop = winit::event_loop::EventLoop::new().unwrap();
    event_loop.set_control_flow(winit::event_loop::ControlFlow::Poll);
    let _window = event_loop
        .create_window(WindowAttributes::default())
        .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();
}
source

pub fn pressed(&self, action: impl Into<usize>) -> bool

checks if action was just pressed. same as self.pressed[action.into()]

Examples found in repository?
examples/example.rs (line 51)
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
74
75
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::WindowAttributes};
    let event_loop = winit::event_loop::EventLoop::new().unwrap();
    event_loop.set_control_flow(winit::event_loop::ControlFlow::Poll);
    let _window = event_loop
        .create_window(WindowAttributes::default())
        .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();
}
source

pub fn released(&self, action: impl Into<usize>) -> bool

checks if action was just released. same as self.released[action.into()]

Examples found in repository?
examples/example.rs (line 63)
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
74
75
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::WindowAttributes};
    let event_loop = winit::event_loop::EventLoop::new().unwrap();
    event_loop.set_control_flow(winit::event_loop::ControlFlow::Poll);
    let _window = event_loop
        .create_window(WindowAttributes::default())
        .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();
}
source

pub fn axis(&self, pos: impl Into<usize>, neg: impl Into<usize>) -> f32

returns 1.0 if pos is pressed, -1.0 if neg is pressed or 0.0 if either pos and neg or nothing is pressed. usefull for movement controls. same as input::axis(input.pressing(pos), input.pressing(neg))

let move_dir = (input.axis(Right, Left), input.axis(Up, Down));
Examples found in repository?
examples/example.rs (line 55)
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
74
75
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::WindowAttributes};
    let event_loop = winit::event_loop::EventLoop::new().unwrap();
    event_loop.set_control_flow(winit::event_loop::ControlFlow::Poll);
    let _window = event_loop
        .create_window(WindowAttributes::default())
        .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();
}

Auto Trait Implementations§

§

impl<const BINDS: usize> Freeze for InputMap<BINDS>

§

impl<const BINDS: usize> RefUnwindSafe for InputMap<BINDS>

§

impl<const BINDS: usize> Send for InputMap<BINDS>

§

impl<const BINDS: usize> Sync for InputMap<BINDS>

§

impl<const BINDS: usize> Unpin for InputMap<BINDS>

§

impl<const BINDS: usize> UnwindSafe for InputMap<BINDS>

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> 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> Downcast for T
where T: Any,

source§

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>

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)

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)

Convert &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
where T: Any + Send + Sync,

source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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, U> TryFrom<U> for T
where U: Into<T>,

§

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>,

§

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<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more