From 617840f62bbb9b0caf73a0a049db813ca0219a7c Mon Sep 17 00:00:00 2001 From: Dennis Brakhane Date: Thu, 19 Sep 2024 16:03:28 +0200 Subject: [PATCH] Fix keyboard inputs on SDL (#946) input: fix keyboard inputs on SDL --- WickedEngine/wiInput.cpp | 2 +- WickedEngine/wiInput.h | 7 ++++++- WickedEngine/wiSDLInput.cpp | 10 +++++----- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/WickedEngine/wiInput.cpp b/WickedEngine/wiInput.cpp index 1cfb80179..9d882f572 100644 --- a/WickedEngine/wiInput.cpp +++ b/WickedEngine/wiInput.cpp @@ -435,7 +435,7 @@ namespace wi::input } else if (playerindex == 0) // keyboard or mouse { - uint8_t keycode = (uint8_t)button; + uint16_t keycode = (uint16_t)button; switch (button) { diff --git a/WickedEngine/wiInput.h b/WickedEngine/wiInput.h index ba9556e6e..4da3a4cf6 100644 --- a/WickedEngine/wiInput.h +++ b/WickedEngine/wiInput.h @@ -12,6 +12,8 @@ namespace wi::input { BUTTON_NONE = 0, + DIGIT_RANGE_START = 48, // digit 0 + CHARACTER_RANGE_START = 65, // letter A GAMEPAD_RANGE_START = 256, // do not use! @@ -114,6 +116,9 @@ namespace wi::input KEYBOARD_BUTTON_TAB, KEYBOARD_BUTTON_TILDE, KEYBOARD_BUTTON_INSERT, + + // must be the last entry + BUTTON_ENUM_SIZE }; enum GAMEPAD_ANALOG { @@ -125,7 +130,7 @@ namespace wi::input struct KeyboardState { - bool buttons[256] = {}; // it contains pressed buttons as "keyboard/typewriter" like, so no continuous presses + bool buttons[BUTTON_ENUM_SIZE] = {}; // it contains pressed buttons as "keyboard/typewriter" like, so no continuous presses }; struct MouseState { diff --git a/WickedEngine/wiSDLInput.cpp b/WickedEngine/wiSDLInput.cpp index f6781ba65..02216dda1 100644 --- a/WickedEngine/wiSDLInput.cpp +++ b/WickedEngine/wiSDLInput.cpp @@ -239,16 +239,16 @@ namespace wi::input::sdlinput // Scancode Conversion Segment if(key >= 4 && key <= 29){ // A to Z - return key+61; + return (key - 4) + CHARACTER_RANGE_START; } - if(key >= 30 && key <= 39){ // 0 to 10 - return key+18; + if(key >= 30 && key <= 39){ // 0 to 9 + return (key - 30) + DIGIT_RANGE_START; } if(key >= 58 && key <= 69){ // F1 to F12 - return key-47; + return (key - 58) + KEYBOARD_BUTTON_F1; } if(key >= 79 && key <= 82){ // Keyboard directional buttons - return (82-key)+4; + return (82 - key) + KEYBOARD_BUTTON_UP; } switch(key){ // Individual scancode key conversion case SDL_SCANCODE_SPACE: