Fix keyboard inputs on SDL (#946)

input: fix keyboard inputs on SDL
This commit is contained in:
Dennis Brakhane
2024-09-19 16:03:28 +02:00
committed by GitHub
parent e8d656ef9a
commit 617840f62b
3 changed files with 12 additions and 7 deletions
+1 -1
View File
@@ -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)
{
+6 -1
View File
@@ -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
{
+5 -5
View File
@@ -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: