From 002dae6826066ea344b26b4788bd980a5ff8fa36 Mon Sep 17 00:00:00 2001 From: Rekai Musuka Date: Tue, 3 Aug 2021 20:23:43 -0500 Subject: [PATCH] fix(joypad): improve handling of keyboard input --- src/joypad.rs | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/joypad.rs b/src/joypad.rs index 66537df..06cc9f5 100644 --- a/src/joypad.rs +++ b/src/joypad.rs @@ -120,49 +120,57 @@ pub fn handle_keyboard_input(pad: &mut Joypad, input: &WinitInputHelper) { if input.key_pressed(VirtualKeyCode::Down) { state.dpad_down.update(true, irq); - } else if input.key_released(VirtualKeyCode::Down) { + } + if input.key_released(VirtualKeyCode::Down) { state.dpad_down.update(false, irq); } if input.key_pressed(VirtualKeyCode::Up) { state.dpad_up.update(true, irq); - } else if input.key_released(VirtualKeyCode::Up) { + } + if input.key_released(VirtualKeyCode::Up) { state.dpad_up.update(false, irq); } if input.key_pressed(VirtualKeyCode::Left) { state.dpad_left.update(true, irq); - } else if input.key_released(VirtualKeyCode::Left) { + } + if input.key_released(VirtualKeyCode::Left) { state.dpad_left.update(false, irq); } if input.key_pressed(VirtualKeyCode::Right) { state.dpad_right.update(true, irq); - } else if input.key_released(VirtualKeyCode::Right) { + } + if input.key_released(VirtualKeyCode::Right) { state.dpad_right.update(false, irq); } if input.key_pressed(VirtualKeyCode::T) { state.start.update(true, irq); - } else if input.key_released(VirtualKeyCode::T) { + } + if input.key_released(VirtualKeyCode::T) { state.start.update(false, irq); } if input.key_pressed(VirtualKeyCode::Y) { state.select.update(true, irq); - } else if input.key_released(VirtualKeyCode::Y) { + } + if input.key_released(VirtualKeyCode::Y) { state.select.update(false, irq); } if input.key_pressed(VirtualKeyCode::Z) { state.south.update(true, irq); - } else if input.key_released(VirtualKeyCode::Z) { + } + if input.key_released(VirtualKeyCode::Z) { state.south.update(false, irq); } if input.key_pressed(VirtualKeyCode::X) { state.east.update(true, irq); - } else if input.key_released(VirtualKeyCode::X) { + } + if input.key_released(VirtualKeyCode::X) { state.east.update(false, irq); } }