send_unicode.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. // Written by konstantin: vomindoraan
  2. #include "send_unicode.h"
  3. #include <ctype.h>
  4. #include <string.h>
  5. __attribute__((weak))
  6. void send_unicode_hex_string(const char* str) {
  7. if (!str) { return; } // Safety net
  8. while (*str) {
  9. // Find the next code point (token) in the string
  10. for (; *str == ' '; str++);
  11. size_t n = strcspn(str, " "); // Length of the current token
  12. char code_point[n+1];
  13. strncpy(code_point, str, n);
  14. code_point[n] = '\0'; // Make sure it's null-terminated
  15. // Normalize the code point: make all hex digits lowercase
  16. for (char *p = code_point; *p; p++) {
  17. *p = tolower((unsigned char)*p);
  18. }
  19. // Send the code point as a Unicode input string
  20. unicode_input_start();
  21. send_string(code_point);
  22. unicode_input_finish();
  23. str += n; // Move to the first ' ' (or '\0') after the current token
  24. }
  25. }
  26. // (ノಠ痊ಠ)ノ彡┻━┻
  27. // send_unicode_hex_string("0028 30CE 0CA0 75CA 0CA0 0029 30CE 5F61 253B 2501 253B");
  28. //Old code
  29. // (╯°□°)╯ ︵ ┻━┻
  30. #if 0
  31. register_code(KC_RSFT);
  32. tap(KC_9);
  33. unregister_code(KC_RSFT);
  34. process_unicode((0x256F | QK_UNICODE), record); // Arm
  35. process_unicode((0x00B0 | QK_UNICODE), record); // Eye
  36. process_unicode((0x25A1 | QK_UNICODE), record); // Mouth
  37. process_unicode((0x00B0 | QK_UNICODE), record); // Eye
  38. register_code(KC_RSFT);
  39. tap(KC_0);
  40. unregister_code(KC_RSFT);
  41. process_unicode((0x256F | QK_UNICODE), record); // Arm
  42. tap(KC_SPC);
  43. process_unicode((0x0361 | QK_UNICODE), record); // Flippy
  44. tap(KC_SPC);
  45. process_unicode((0x253B | QK_UNICODE), record); // Table
  46. process_unicode((0x2501 | QK_UNICODE), record); // Table
  47. process_unicode((0x253B | QK_UNICODE), record); // Table
  48. #endif
  49. // If you need a good converter: https://r12a.github.io/app-conversion/
  50. uint8_t saved_mods;
  51. void unicode_input_start (void) {
  52. // save current mods
  53. saved_mods = get_mods(); // Save current mods
  54. clear_mods(); // Unregister mods to start from a clean state
  55. switch(get_unicode_input_mode()) {
  56. case UC_OSX:
  57. register_code(KC_LALT);
  58. break;
  59. case UC_LNX:
  60. register_code(KC_LCTL);
  61. register_code(KC_LSFT);
  62. register_code(KC_U);
  63. unregister_code(KC_U);
  64. unregister_code(KC_LSFT);
  65. unregister_code(KC_LCTL);
  66. break;
  67. case UC_WIN:
  68. register_code(KC_LALT);
  69. register_code(KC_PPLS);
  70. unregister_code(KC_PPLS);
  71. break;
  72. case UC_WINC:
  73. register_code(KC_RALT);
  74. unregister_code(KC_RALT);
  75. register_code(KC_U);
  76. unregister_code(KC_U);
  77. break;
  78. }
  79. wait_ms(UNICODE_TYPE_DELAY);
  80. }
  81. void unicode_input_finish (void) {
  82. switch(get_unicode_input_mode()) {
  83. case UC_OSX:
  84. case UC_WIN:
  85. unregister_code(KC_LALT);
  86. break;
  87. case UC_LNX:
  88. register_code(KC_SPC);
  89. unregister_code(KC_SPC);
  90. break;
  91. }
  92. set_mods(saved_mods); // Reregister previously set mods
  93. }