test/checkkeys.c
changeset 9278 8900afb78a19
parent 8149 681eb46b8ac4
child 9580 d37ef6990bf9
     1.1 --- a/test/checkkeys.c	Sat Dec 13 02:33:52 2014 -0500
     1.2 +++ b/test/checkkeys.c	Thu Dec 18 00:19:52 2014 -0500
     1.3 @@ -19,8 +19,14 @@
     1.4  #include <stdlib.h>
     1.5  #include <string.h>
     1.6  
     1.7 +#ifdef __EMSCRIPTEN__
     1.8 +#include <emscripten/emscripten.h>
     1.9 +#endif
    1.10 +
    1.11  #include "SDL.h"
    1.12  
    1.13 +int done;
    1.14 +
    1.15  /* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
    1.16  static void
    1.17  quit(int rc)
    1.18 @@ -128,12 +134,37 @@
    1.19      SDL_Log("Text (%s): \"%s%s\"\n", expanded, *text == '"' ? "\\" : "", text);
    1.20  }
    1.21  
    1.22 +void
    1.23 +loop()
    1.24 +{
    1.25 +    SDL_Event event;
    1.26 +    /* Check for events */
    1.27 +    /*SDL_WaitEvent(&event); emscripten does not like waiting*/
    1.28 +
    1.29 +    while (SDL_PollEvent(&event)) {
    1.30 +        switch (event.type) {
    1.31 +        case SDL_KEYDOWN:
    1.32 +        //case SDL_KEYUP:
    1.33 +		    PrintKey(&event.key.keysym, (event.key.state == SDL_PRESSED) ? SDL_TRUE : SDL_FALSE, (event.key.repeat) ? SDL_TRUE : SDL_FALSE);
    1.34 +            break;
    1.35 +        case SDL_TEXTINPUT:
    1.36 +            PrintText(event.text.text);
    1.37 +            break;
    1.38 +        case SDL_MOUSEBUTTONDOWN:
    1.39 +            /* Any button press quits the app... */
    1.40 +        case SDL_QUIT:
    1.41 +            done = 1;
    1.42 +            break;
    1.43 +        default:
    1.44 +            break;
    1.45 +        }
    1.46 +    }
    1.47 +}
    1.48 +
    1.49  int
    1.50  main(int argc, char *argv[])
    1.51  {
    1.52      SDL_Window *window;
    1.53 -    SDL_Event event;
    1.54 -    int done;
    1.55  	
    1.56  	/* Enable standard application logging */
    1.57  	SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
    1.58 @@ -163,26 +194,14 @@
    1.59  
    1.60      /* Watch keystrokes */
    1.61      done = 0;
    1.62 +
    1.63 +#ifdef __EMSCRIPTEN__
    1.64 +    emscripten_set_main_loop(loop, 0, 1);
    1.65 +#else
    1.66      while (!done) {
    1.67 -        /* Check for events */
    1.68 -        SDL_WaitEvent(&event);
    1.69 -        switch (event.type) {
    1.70 -        case SDL_KEYDOWN:
    1.71 -        case SDL_KEYUP:
    1.72 -			PrintKey(&event.key.keysym, (event.key.state == SDL_PRESSED) ? SDL_TRUE : SDL_FALSE, (event.key.repeat) ? SDL_TRUE : SDL_FALSE);
    1.73 -            break;
    1.74 -        case SDL_TEXTINPUT:
    1.75 -            PrintText(event.text.text);
    1.76 -            break;
    1.77 -        case SDL_MOUSEBUTTONDOWN:
    1.78 -            /* Any button press quits the app... */
    1.79 -        case SDL_QUIT:
    1.80 -            done = 1;
    1.81 -            break;
    1.82 -        default:
    1.83 -            break;
    1.84 -        }
    1.85 +        loop();
    1.86      }
    1.87 +#endif
    1.88  
    1.89      SDL_Quit();
    1.90      return (0);