SDL_scancode_tables.c 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2022 Sam Lantinga <[email protected]>
  4. This software is provided 'as-is', without any express or implied
  5. warranty. In no event will the authors be held liable for any damages
  6. arising from the use of this software.
  7. Permission is granted to anyone to use this software for any purpose,
  8. including commercial applications, and to alter it and redistribute it
  9. freely, subject to the following restrictions:
  10. 1. The origin of this software must not be misrepresented; you must not
  11. claim that you wrote the original software. If you use this software
  12. in a product, an acknowledgment in the product documentation would be
  13. appreciated but is not required.
  14. 2. Altered source versions must be plainly marked as such, and must not be
  15. misrepresented as being the original software.
  16. 3. This notice may not be removed or altered from any source distribution.
  17. */
  18. #include "../SDL_internal.h"
  19. #if SDL_INPUT_LINUXEV || SDL_VIDEO_DRIVER_WAYLAND || SDL_VIDEO_DRIVER_X11
  20. #include "SDL_scancode_tables_c.h"
  21. #include "scancodes_darwin.h"
  22. #include "scancodes_linux.h"
  23. #include "scancodes_xfree86.h"
  24. static const struct
  25. {
  26. SDL_ScancodeTable table;
  27. SDL_Scancode const *scancodes;
  28. int num_entries;
  29. } SDL_scancode_tables[] = {
  30. { SDL_SCANCODE_TABLE_DARWIN, darwin_scancode_table, SDL_arraysize(darwin_scancode_table) },
  31. { SDL_SCANCODE_TABLE_LINUX, linux_scancode_table, SDL_arraysize(linux_scancode_table) },
  32. { SDL_SCANCODE_TABLE_XFREE86_1, xfree86_scancode_table, SDL_arraysize(xfree86_scancode_table) },
  33. { SDL_SCANCODE_TABLE_XFREE86_2, xfree86_scancode_table2, SDL_arraysize(xfree86_scancode_table2) },
  34. { SDL_SCANCODE_TABLE_XVNC, xvnc_scancode_table, SDL_arraysize(xvnc_scancode_table) },
  35. };
  36. const SDL_Scancode *SDL_GetScancodeTable(SDL_ScancodeTable table, int *num_entries)
  37. {
  38. int i;
  39. for (i = 0; i < SDL_arraysize(SDL_scancode_tables); ++i) {
  40. if (table == SDL_scancode_tables[i].table) {
  41. *num_entries = SDL_scancode_tables[i].num_entries;
  42. return SDL_scancode_tables[i].scancodes;
  43. }
  44. }
  45. *num_entries = 0;
  46. return NULL;
  47. }
  48. SDL_Scancode SDL_GetScancodeFromTable(SDL_ScancodeTable table, int keycode)
  49. {
  50. SDL_Scancode scancode = SDL_SCANCODE_UNKNOWN;
  51. int num_entries;
  52. const SDL_Scancode *scancodes = SDL_GetScancodeTable(table, &num_entries);
  53. if (keycode >= 0 && keycode < num_entries) {
  54. scancode = scancodes[keycode];
  55. }
  56. return scancode;
  57. }
  58. #endif /* SDL_INPUT_LINUXEV || SDL_VIDEO_DRIVER_WAYLAND || SDL_VIDEO_DRIVER_X11 */
  59. /* vi: set ts=4 sw=4 expandtab: */