Created
April 9, 2019 15:46
-
-
Save kolen/31b7b064e90ec32c30f4267c025f49d6 to your computer and use it in GitHub Desktop.
SDL2 keyboard event test script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <SDL.h> | |
int main(int argc, char *argv[]) { | |
SDL_Init(SDL_INIT_VIDEO|SDL_INIT_EVENTS); | |
SDL_Window *window = NULL; | |
window = SDL_CreateWindow("title", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 512, 512, SDL_WINDOW_OPENGL); | |
SDL_Event event; | |
while(1) { | |
while(SDL_PollEvent(&event)) { | |
switch (event.type) { | |
case SDL_KEYUP: | |
printf("keyup "); | |
goto keyinfo; | |
case SDL_KEYDOWN: | |
printf("keydown "); | |
keyinfo: | |
printf("pressed? %d released? %d ", event.key.state == SDL_PRESSED, event.key.state == SDL_RELEASED); | |
printf("repeat? %d ", event.key.repeat); | |
printf("scancode %d keycode %d ", event.key.keysym.scancode, event.key.keysym.sym); | |
printf("mod %d", event.key.keysym.mod); | |
printf("\n"); | |
break; | |
case SDL_QUIT: | |
return 0; | |
} | |
} | |
} | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
clang `sdl2-config --cflags --libs` sdl_input_test.c -osdl_input_test && ./sdl_input_test |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment