Last active
September 6, 2015 00:28
-
-
Save aginor/92afdf5da9dc2bfd5f41 to your computer and use it in GitHub Desktop.
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
/** | |
* Copyright 2015 Andreas Löf | |
* | |
* Compilation: gcc -o keyboardtest -lSDL2 keyboardtest.c | |
* | |
* This program is free software: you can redistribute it and/or | |
* modify it under the terms of the GNU General Public License as | |
* published by the Free Software Foundation, either version 3 of the | |
* License, or (at your option) any later version. | |
* | |
* This program is distributed in the hope that it will be useful, | |
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
* GNU General Public License for more details. | |
* | |
* You should have received a copy of the GNU General Public License | |
* along with this program. If not, see <http://www.gnu.org/licenses/>. | |
*/ | |
#include <stdio.h> | |
#include <SDL2/SDL.h> | |
#define WIDTH 800 | |
#define HEIGHT 600 | |
int main (int argc, char *argv[]) { | |
// variable declarations | |
SDL_Window *win = NULL; | |
SDL_Renderer* renderer; | |
// Initialize SDL. | |
if (SDL_Init(SDL_INIT_VIDEO) < 0) | |
return 1; | |
// create the window | |
win = SDL_CreateWindow("Keyboard test", 0, 0, WIDTH, HEIGHT, 0); | |
renderer = SDL_CreateRenderer(win, -1, 0); | |
SDL_SetRenderDrawColor(renderer, 125, 125, 125, 255); | |
SDL_RenderClear(renderer); | |
SDL_RenderPresent(renderer); | |
// main loop | |
while (1) { | |
// event handling | |
SDL_Event e; | |
if ( SDL_PollEvent(&e) ) { | |
if (e.type == SDL_QUIT) | |
break; | |
else if (e.type == SDL_KEYUP && e.key.keysym.sym == SDLK_ESCAPE) | |
break; | |
if (e.type == SDL_KEYUP) | |
printf("keypress: %d->%s (%s)\n", e.key.keysym.mod, | |
SDL_GetKeyName(e.key.keysym.sym), | |
SDL_GetScancodeName(e.key.keysym.scancode)); | |
} | |
SDL_UpdateWindowSurface(win); | |
SDL_Delay(10); | |
} | |
SDL_DestroyWindow(win); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment