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