Created
July 20, 2013 00:52
-
-
Save ToadKing/6043350 to your computer and use it in GitHub Desktop.
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
| #include <stdio.h> | |
| #include <stdlib.h> | |
| #include <SDL/SDL.h> | |
| #ifdef EMSCRIPTEN | |
| #include <emscripten/emscripten.h> | |
| // bug - SDL_GetKeyboardState doesn't return scancodes, it returns keycodes, so acts exactly like | |
| // SDL_GetKeyState instead | |
| #define SDL_GetKeyState SDL_GetKeyboardState | |
| #endif | |
| void loop() | |
| { | |
| unsigned i; | |
| #ifdef EMSCRIPTEN | |
| SDL_Event e; | |
| while (SDL_PollEvent(&e)); | |
| #else | |
| // emscripten should also have PumpEvents actually run all the events, but that's another issue | |
| SDL_PumpEvents(); | |
| #endif | |
| int num; | |
| const Uint8 *keys = SDL_GetKeyState(&num); | |
| if (keys[SDLK_ESCAPE]) | |
| exit(0); | |
| for (i = 0; i < 256; i++) | |
| if (keys[i] != 0) | |
| printf("key %u\n", i); | |
| } | |
| int main(int argc, char *argv[]) | |
| { | |
| SDL_Init(SDL_INIT_EVERYTHING); | |
| SDL_SetVideoMode(600, 400, 32, SDL_SWSURFACE); | |
| #ifdef EMSCRIPTEN | |
| emscripten_set_main_loop(loop, 0, 0); | |
| #else | |
| while (1) | |
| loop(); | |
| #endif | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment