Skip to content

Commit

Permalink
Add support for numpad (#45)
Browse files Browse the repository at this point in the history
* Add support for numpad keys

* Add numpad keys 4 and 6 to control ship

* Format space_invaders.rs
  • Loading branch information
dancavolix authored May 7, 2024
1 parent 09c0237 commit 9d560c9
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
4 changes: 2 additions & 2 deletions examples/space_invaders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,8 @@ fn main() {

for key_down in app_state.keyboard().get_keys_down() {
match key_down {
Key::A | Key::H => state.spaceship_move_x(-1),
Key::D | Key::L => state.spaceship_move_x(1),
Key::A | Key::H | Key::Numpad4 => state.spaceship_move_x(-1),
Key::D | Key::L | Key::Numpad6 => state.spaceship_move_x(1),
Key::Space => state.spaceship_shot(app_state.step()),
_ => (),
}
Expand Down
21 changes: 21 additions & 0 deletions src/keyboard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,16 @@ pub enum Key {
Num7,
Num8,
Num9,
Numpad0,
Numpad1,
Numpad2,
Numpad3,
Numpad4,
Numpad5,
Numpad6,
Numpad7,
Numpad8,
Numpad9,
F1,
F2,
F3,
Expand Down Expand Up @@ -448,6 +458,17 @@ impl Keyboard {
dq::Keycode::Key8 => Key::Num8,
dq::Keycode::Key9 => Key::Num9,

dq::Keycode::Numpad0 => Key::Numpad0,
dq::Keycode::Numpad1 => Key::Numpad1,
dq::Keycode::Numpad2 => Key::Numpad2,
dq::Keycode::Numpad3 => Key::Numpad3,
dq::Keycode::Numpad4 => Key::Numpad4,
dq::Keycode::Numpad5 => Key::Numpad5,
dq::Keycode::Numpad6 => Key::Numpad6,
dq::Keycode::Numpad7 => Key::Numpad7,
dq::Keycode::Numpad8 => Key::Numpad8,
dq::Keycode::Numpad9 => Key::Numpad9,

dq::Keycode::F1 => Key::F1,
dq::Keycode::F2 => Key::F2,
dq::Keycode::F3 => Key::F3,
Expand Down

0 comments on commit 9d560c9

Please sign in to comment.