kbd.h 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #pragma once
  2. #define KBD_SCAN_DOWN 0x50
  3. #define KBD_SCAN_UP 0x48
  4. #define KBD_SCAN_LEFT 0x4B
  5. #define KBD_SCAN_RIGHT 0x4D
  6. #define KBD_SCAN_ENTER 0x1C
  7. #define KBD_SCAN_1 2
  8. #define KBD_SCAN_9 10
  9. #ifdef EFI_PLATFORM
  10. static int read_scancode(void) {
  11. EFI_INPUT_KEY Key;
  12. unsigned long int index;
  13. uefi_call_wrapper(ST->BootServices->WaitForEvent, 3, 1, &ST->ConIn->WaitForKey, &index);
  14. uefi_call_wrapper(ST->ConIn->ReadKeyStroke, 2, ST->ConIn, &Key);
  15. switch (Key.ScanCode) {
  16. case 0:
  17. switch (Key.UnicodeChar) {
  18. case L'\r':
  19. return KBD_SCAN_ENTER;
  20. case L'1':
  21. case L'2':
  22. case L'3':
  23. case L'4':
  24. case L'5':
  25. case L'6':
  26. case L'7':
  27. case L'8':
  28. case L'9':
  29. return Key.UnicodeChar - L'1' + KBD_SCAN_1;
  30. case L'y':
  31. return 'y';
  32. case L'n':
  33. return 'n';
  34. default:
  35. return 0xFF;
  36. }
  37. break;
  38. case 0x01: return KBD_SCAN_UP;
  39. case 0x02: return KBD_SCAN_DOWN;
  40. case 0x03: return KBD_SCAN_RIGHT;
  41. case 0x04: return KBD_SCAN_LEFT;
  42. default:
  43. return 0xFF;
  44. }
  45. }
  46. #else
  47. static int read_scancode(void) {
  48. while (!(inportb(0x64) & 1));
  49. int out;
  50. while (inportb(0x64) & 1) {
  51. out = inportb(0x60);
  52. }
  53. return out;
  54. }
  55. #endif