process_unicode.c 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #include "process_unicode.h"
  2. static uint8_t input_mode;
  3. uint16_t hex_to_keycode(uint8_t hex)
  4. {
  5. if (hex == 0x0) {
  6. return KC_0;
  7. } else if (hex < 0xA) {
  8. return KC_1 + (hex - 0x1);
  9. } else {
  10. return KC_A + (hex - 0xA);
  11. }
  12. }
  13. void set_unicode_mode(uint8_t os_target)
  14. {
  15. input_mode = os_target;
  16. }
  17. bool process_unicode(uint16_t keycode, keyrecord_t *record) {
  18. if (keycode > QK_UNICODE && record->event.pressed) {
  19. uint16_t unicode = keycode & 0x7FFF;
  20. switch(input_mode) {
  21. case UC_OSX:
  22. register_code(KC_LALT);
  23. break;
  24. case UC_LNX:
  25. register_code(KC_LCTL);
  26. register_code(KC_LSFT);
  27. register_code(KC_U);
  28. unregister_code(KC_U);
  29. break;
  30. case UC_WIN:
  31. register_code(KC_LALT);
  32. register_code(KC_PPLS);
  33. unregister_code(KC_PPLS);
  34. break;
  35. }
  36. for(int i = 3; i >= 0; i--) {
  37. uint8_t digit = ((unicode >> (i*4)) & 0xF);
  38. register_code(hex_to_keycode(digit));
  39. unregister_code(hex_to_keycode(digit));
  40. }
  41. switch(input_mode) {
  42. case UC_OSX:
  43. case UC_WIN:
  44. unregister_code(KC_LALT);
  45. break;
  46. case UC_LNX:
  47. unregister_code(KC_LCTL);
  48. unregister_code(KC_LSFT);
  49. break;
  50. }
  51. }
  52. return true;
  53. }