diff options
| author | ladevieq <ladevie.quentin@gmail.com> | 2021-01-25 20:29:22 +0100 |
|---|---|---|
| committer | ladevieq <ladevie.quentin@gmail.com> | 2021-01-25 20:32:53 +0100 |
| commit | c730c0214abfe851555df5793d4aca82782be1d0 (patch) | |
| tree | 8c8c4d83474d00da97b5ab2be1d0c57bd3a874b2 /src/window.cpp | |
| parent | 2cd8461c738e857f054f4c65c0a1baf8bb9ba5b3 (diff) | |
Fix input handling for Windows
Windows generate keydown events for the last pressed key only
If we are pressing two key together this is troublesome as we don't get
notified we are pressing two keys
Fixed by updating an array of key states on key down/release and
generating event while the key state is pressed
Diffstat (limited to 'src/window.cpp')
| -rw-r--r-- | src/window.cpp | 31 |
1 files changed, 19 insertions, 12 deletions
diff --git a/src/window.cpp b/src/window.cpp index 273d7e9..840d570 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -227,6 +227,17 @@ window::~window() {} void window::poll_events() { MSG msg = {}; + // Generate keydown events pressed keys + for (size_t virtual_key = KEYS::SHIFT; virtual_key < KEYS::MAX_KEYS; virtual_key++) { + if (keyboard[virtual_key]) { + events.push_back({ + .key = (KEYS)virtual_key, + .type = EVENT_TYPES::KEY_PRESS, + }); + } + } + + while (PeekMessage(&msg, win_handle, 0, 0, PM_REMOVE)) { TranslateMessage(&msg); DispatchMessage(&msg); @@ -255,26 +266,22 @@ LRESULT window::message_handler(HWND hwnd, UINT umsg, WPARAM wparam, LPARAM lpar } case WM_KEYDOWN: { - auto key_press_event = event { - .key = (KEYS)wparam, - .type = EVENT_TYPES::KEY_PRESS, - }; - keyboard[wparam] = true; - events.push_back(key_press_event); + events.push_back({ + .key = (KEYS)wparam, + .type = EVENT_TYPES::KEY_PRESS, + }); break; } case WM_KEYUP: { - auto key_press_event = event { - .key = (KEYS)wparam, - .type = EVENT_TYPES::KEY_RELEASE, - }; - keyboard[wparam] = false; - events.push_back(key_press_event); + events.push_back({ + .key = (KEYS)wparam, + .type = EVENT_TYPES::KEY_RELEASE, + }); break; } |
