Im writing a program using SDL (libsdl2-dev (version: 2.0.14+dfsg2-3+deb11u1)). I have a keyboard event handler that has been working well for me when I ran into an issue using certain keystroke combinations. After simplifying the code to print just the states of the "end", "home", "page up", "page down", "insert" and "delete" key states from SDL_GetKeyboardState, the issue was still present.
For example, if I press the "end" key button, I can see my print out change from 0 to "pressed". The bug was discovered when using the SDL_SCANCODE_KP_PLUS + SDL_SCANCODE_KP_9. So i tried holding those two keys down, then pressing the "end" key. My screen never printed that I pressed the "end" key. They are seemingly random combinations to me also.
Here are a few that do not work.
SDL_SCANCODE_KP_PLUS + SDL_SCANCODE_KP_9:
SDL_SCANCODE_HOME
SDL_SCANCODE_END
SDL_SCANCODE_PAGEDOWN
SDL_SCANCODE_PAGEUP
SDL_SCANCODE_KP_PLUS + SDL_SCANCODE_KP_8:
SDL_SCANCODE_HOME
SDL_SCANCODE_END
SDL_SCANCODE_INSERT
SDL_SCANCODE_KP_PLUS + SDL_SCANCODE_KP_7:
SDL_SCANCODE_HOME
SDL_SCANCODE_END
SDL_SCANCODE_INSERT
SDL_SCANCODE_DELETE
The other keypad numbers have no issue with like what i am seeing with keypad 7, 8, and 9. Here is my code I used to observe the issue:
#include <SDL2/SDL.h>
#include <iostream>
#include <map>
int main(int argc, char* argv[]) {
SDL_Init(SDL_INIT_VIDEO);
SDL_Window* window = SDL_CreateWindow(
"Keyboard State Monitor",
SDL_WINDOWPOS_UNDEFINED,
SDL_WINDOWPOS_UNDEFINED,
640,
480,
0
);
SDL_Event event;
bool running = true;
while (running) {
while (SDL_PollEvent(&event)) {
if (event.type == SDL_QUIT) {
running = false;
}
}
// Get the current state of all keys
const Uint8* currentKeyState = SDL_GetKeyboardState(NULL);
// Keys to monitor
std::map<SDL_Scancode, const char*> keysToMonitor = {
{SDL_SCANCODE_END, "End"},
{SDL_SCANCODE_HOME, "Home"},
{SDL_SCANCODE_PAGEUP, "Page Up"},
{SDL_SCANCODE_PAGEDOWN, "Page Down"},
{SDL_SCANCODE_DELETE, "Delete"},
{SDL_SCANCODE_INSERT, "Insert"}
};
// Print the state of monitored keys
std::cout << "\nKey State:" << std::endl;
for (const auto& entry : keysToMonitor) {
SDL_Scancode scancode = entry.first;
const char* keyName = entry.second;
if (currentKeyState[scancode]) {
std::cout << keyName << ": YES" << std::endl;
} else {
std::cout << keyName << ": 0" << std::endl;
}
}
SDL_Delay(100); // To prevent the loop from running too fast
}
SDL_DestroyWindow(window);
SDL_Quit();
return 0;
}
Here is my compile command:
g++ -o pressed_check IsPressedCheck.cc -lSDL2
I only see it when combining keypad 7, 8, or 9 with the "plus sign" keypad button. I have yet to find any other key combo's that are not working. This issue occurred on my raspberry pi running Bullseye. But it was reproduced in my WSL environment on my windows 10 laptop, which is set up to mirror my PI setup.
p.s. this occurs with num lock On && Off.