Created
August 21, 2023 16:59
-
-
Save masatoi/eba0af8492ad4141cb3147f76056b9e6 to your computer and use it in GitHub Desktop.
Output Key Event tool for SDL2
This file contains hidden or 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
/* | |
sudo apt install libsdl2-dev | |
gcc keyevent.c -o keyevent -lSDL2 | |
*/ | |
#include <SDL2/SDL.h> | |
#include <stdbool.h> | |
int main(int argc, char* argv[]) { | |
SDL_Init(SDL_INIT_VIDEO); | |
SDL_Window* window = SDL_CreateWindow("Key Event Test", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 640, 480, 0); | |
SDL_Renderer* renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED); | |
SDL_Event event; | |
bool quit = false; | |
while (!quit) { | |
while (SDL_PollEvent(&event)) { | |
if (event.type == SDL_QUIT) { | |
quit = true; | |
} else if (event.type == SDL_KEYDOWN) { | |
printf("Key pressed:\n"); | |
printf(" Name: %s\n", SDL_GetKeyName(event.key.keysym.sym)); | |
printf(" Scancode: %d\n", event.key.keysym.scancode); | |
printf(" Virtual Keycode: %d\n", event.key.keysym.sym); | |
printf(" Modifiers: 0x%X\n", event.key.keysym.mod); | |
} | |
} | |
} | |
SDL_DestroyRenderer(renderer); | |
SDL_DestroyWindow(window); | |
SDL_Quit(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment