Skip to content

Commit

Permalink
Fix the crash caused by the key press (veeenu#175)
Browse files Browse the repository at this point in the history
  • Loading branch information
vsylva authored Mar 14, 2024
1 parent f8fc75d commit f058304
Showing 1 changed file with 11 additions and 14 deletions.
25 changes: 11 additions & 14 deletions src/renderer/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,26 +55,23 @@ fn handle_raw_mouse_input(io: &mut Io, raw_mouse: &RAWMOUSE) {
let button_data = unsafe { raw_mouse.Anonymous.Anonymous };
let button_flags = button_data.usButtonFlags as u32;

let mut event = |flag, button, key, state| {
let mut event = |flag, button, state| {
if (button_flags & flag) != 0 {
io.add_mouse_button_event(button, state);
if let Some(key) = vk_to_imgui(key) {
io.add_key_event(key, state);
}
}
};

// Check whether any of the mouse buttons was pressed or released.
event(RI_MOUSE_LEFT_BUTTON_DOWN, MouseButton::Left, VK_LBUTTON, true);
event(RI_MOUSE_LEFT_BUTTON_UP, MouseButton::Left, VK_LBUTTON, false);
event(RI_MOUSE_RIGHT_BUTTON_DOWN, MouseButton::Right, VK_RBUTTON, true);
event(RI_MOUSE_RIGHT_BUTTON_UP, MouseButton::Right, VK_RBUTTON, false);
event(RI_MOUSE_MIDDLE_BUTTON_DOWN, MouseButton::Middle, VK_MBUTTON, true);
event(RI_MOUSE_MIDDLE_BUTTON_UP, MouseButton::Middle, VK_MBUTTON, false);
event(RI_MOUSE_BUTTON_4_DOWN, MouseButton::Extra1, VK_XBUTTON1, true);
event(RI_MOUSE_BUTTON_4_UP, MouseButton::Extra1, VK_XBUTTON1, false);
event(RI_MOUSE_BUTTON_5_DOWN, MouseButton::Extra2, VK_XBUTTON2, true);
event(RI_MOUSE_BUTTON_5_UP, MouseButton::Extra2, VK_XBUTTON2, false);
event(RI_MOUSE_LEFT_BUTTON_DOWN, MouseButton::Left, true);
event(RI_MOUSE_LEFT_BUTTON_UP, MouseButton::Left, false);
event(RI_MOUSE_RIGHT_BUTTON_DOWN, MouseButton::Right, true);
event(RI_MOUSE_RIGHT_BUTTON_UP, MouseButton::Right, false);
event(RI_MOUSE_MIDDLE_BUTTON_DOWN, MouseButton::Middle, true);
event(RI_MOUSE_MIDDLE_BUTTON_UP, MouseButton::Middle, false);
event(RI_MOUSE_BUTTON_4_DOWN, MouseButton::Extra1, true);
event(RI_MOUSE_BUTTON_4_UP, MouseButton::Extra1, false);
event(RI_MOUSE_BUTTON_5_DOWN, MouseButton::Extra2, true);
event(RI_MOUSE_BUTTON_5_UP, MouseButton::Extra2, false);

// Apply vertical mouse scroll.
let wheel_delta_x = if button_flags & RI_MOUSE_WHEEL != 0 {
Expand Down

0 comments on commit f058304

Please sign in to comment.