u8x8_sdl_key.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #ifndef NO_SDL
  2. #include "SDL.h"
  3. #endif
  4. /* return ascii key value or -1 */
  5. int u8g_sdl_get_key(void)
  6. {
  7. #ifndef NO_SDL
  8. SDL_Event event;
  9. /* https://wiki.libsdl.org/SDL_PollEvent */
  10. if ( SDL_PollEvent(&event) != 0 )
  11. {
  12. switch (event.type)
  13. {
  14. case SDL_QUIT:
  15. exit(0);
  16. break;
  17. case SDL_KEYDOWN:
  18. switch( event.key.keysym.sym )
  19. {
  20. /* /usr/include/SDL/SDL_keysym.h */
  21. /* /usr/include/SDL2/SDL_keycode.h */
  22. case SDLK_a: return 'a';
  23. case SDLK_b: return 'b';
  24. case SDLK_c: return 'c';
  25. case SDLK_d: return 'd';
  26. case SDLK_e: return 'e';
  27. case SDLK_f: return 'f';
  28. case SDLK_g: return 'g';
  29. case SDLK_h: return 'h';
  30. case SDLK_i: return 'i';
  31. case SDLK_j: return 'j';
  32. case SDLK_k: return 'k';
  33. case SDLK_l: return 'l';
  34. case SDLK_m: return 'm';
  35. case SDLK_n: return 'n';
  36. case SDLK_o: return 'o';
  37. case SDLK_p: return 'p';
  38. case SDLK_q: return 'q';
  39. case SDLK_r: return 'r';
  40. case SDLK_s: return 's';
  41. case SDLK_t: return 't';
  42. case SDLK_u: return 'u';
  43. case SDLK_v: return 'v';
  44. case SDLK_w: return 'w';
  45. case SDLK_x: return 'x';
  46. case SDLK_y: return 'y';
  47. case SDLK_z: return 'z';
  48. case SDLK_SPACE: return ' ';
  49. case SDLK_UP: return 273;
  50. case SDLK_DOWN: return 274;
  51. case SDLK_RIGHT: return 275;
  52. case SDLK_LEFT: return 276;
  53. case SDLK_PERIOD: return '.';
  54. default: return 0;
  55. }
  56. }
  57. }
  58. #endif
  59. return -1;
  60. }