When I try to poll the keydown event in SDL 2.0 and hold the key down, I get several key change events one by one. When I try to run the same program using SDL 1.2.15 (with minor changes since SDL 1.2.15 does not support SDL_Window), I do not have this problem. The keydown event occurs only once, as expected. I even tried to run the program on another computer to make sure that this is not a computer problem.
The corresponding code is as follows:
#include <iostream>
#include <SDL.h>
using namespace std;
SDL_Event event;
SDL_Window* screen = NULL;
int main(int argc, char* args[])
{
if(SDL_Init(SDL_INIT_EVERYTHING) == -1)
{
cout << "ERROR INIT";
return 0;
}
screen = SDL_CreateWindow("My Game Window",
SDL_WINDOWPOS_UNDEFINED,
SDL_WINDOWPOS_UNDEFINED,
640, 480,
SDL_WINDOW_OPENGL);
bool quit = false;
while(!quit)
{
while(SDL_PollEvent(&event))
{
if(event.type == SDL_KEYDOWN)
{
cout << "KEY PRESSED!" << endl;
}
}
}
return 0;
}
source
share