diff options
-rw-r--r-- | docs/feature_unicode.md | 7 | ||||
-rw-r--r-- | quantum/process_keycode/process_unicode_common.c | 28 | ||||
-rw-r--r-- | quantum/process_keycode/process_unicode_common.h | 1 |
3 files changed, 35 insertions, 1 deletions
diff --git a/docs/feature_unicode.md b/docs/feature_unicode.md index ecad6c60c..278b93ad7 100644 --- a/docs/feature_unicode.md +++ b/docs/feature_unicode.md | |||
@@ -19,7 +19,7 @@ table. | |||
19 | TBD | 19 | TBD |
20 | 20 | ||
21 | Unicode input in QMK works by inputing a sequence of characters to the OS, | 21 | Unicode input in QMK works by inputing a sequence of characters to the OS, |
22 | sort of like macro. Unfortunately, each OS has different ideas on how Unicode is inputted. | 22 | sort of like macro. Unfortunately, each OS has different ideas on how Unicode is input. |
23 | 23 | ||
24 | This is the current list of Unicode input method in QMK: | 24 | This is the current list of Unicode input method in QMK: |
25 | 25 | ||
@@ -29,6 +29,11 @@ This is the current list of Unicode input method in QMK: | |||
29 | * UC_WIN: (not recommended) Windows built-in Unicode input. To enable: create registry key under `HKEY_CURRENT_USER\Control Panel\Input Method\EnableHexNumpad` of type `REG_SZ` called `EnableHexNumpad`, set its value to 1, and reboot. This method is not recommended because of reliability and compatibility issue, use WinCompose method below instead. | 29 | * UC_WIN: (not recommended) Windows built-in Unicode input. To enable: create registry key under `HKEY_CURRENT_USER\Control Panel\Input Method\EnableHexNumpad` of type `REG_SZ` called `EnableHexNumpad`, set its value to 1, and reboot. This method is not recommended because of reliability and compatibility issue, use WinCompose method below instead. |
30 | * UC_WINC: Windows Unicode input using WinCompose. Requires [WinCompose](https://github.com/samhocevar/wincompose). Works reliably under many (all?) variations of Windows. | 30 | * UC_WINC: Windows Unicode input using WinCompose. Requires [WinCompose](https://github.com/samhocevar/wincompose). Works reliably under many (all?) variations of Windows. |
31 | 31 | ||
32 | To type multiple characters for things like (ノಠ痊ಠ)ノ彡┻━┻, you can use `send_unicode_hex_string()` much like `SEND_STRING()` except you would use hex values seperated by spaces. | ||
33 | For example, the table flip seen above would be `send_unicode_hex_string("0028 30CE 0CA0 75CA 0CA0 0029 30CE 5F61 253B 2501 253B")` | ||
34 | |||
35 | There are many ways to get a hex code, but an easy one is [this site](https://r12a.github.io/app-conversion/). Just make sure to convert to hexadecimal, and that is your string. | ||
36 | |||
32 | # Additional Language Support | 37 | # Additional Language Support |
33 | 38 | ||
34 | In `quantum/keymap_extras/`, you'll see various language files - these work the same way as the alternative layout ones do. Most are defined by their two letter country/language code followed by an underscore and a 4-letter abbreviation of its name. `FR_UGRV` which will result in a `ù` when using a software-implemented AZERTY layout. It's currently difficult to send such characters in just the firmware. | 39 | In `quantum/keymap_extras/`, you'll see various language files - these work the same way as the alternative layout ones do. Most are defined by their two letter country/language code followed by an underscore and a 4-letter abbreviation of its name. `FR_UGRV` which will result in a `ù` when using a software-implemented AZERTY layout. It's currently difficult to send such characters in just the firmware. |
diff --git a/quantum/process_keycode/process_unicode_common.c b/quantum/process_keycode/process_unicode_common.c index 7f34ad57c..e6620b7ea 100644 --- a/quantum/process_keycode/process_unicode_common.c +++ b/quantum/process_keycode/process_unicode_common.c | |||
@@ -16,6 +16,8 @@ | |||
16 | 16 | ||
17 | #include "process_unicode_common.h" | 17 | #include "process_unicode_common.h" |
18 | #include "eeprom.h" | 18 | #include "eeprom.h" |
19 | #include <string.h> | ||
20 | #include <ctype.h> | ||
19 | 21 | ||
20 | static uint8_t input_mode; | 22 | static uint8_t input_mode; |
21 | uint8_t mods; | 23 | uint8_t mods; |
@@ -120,3 +122,29 @@ void register_hex(uint16_t hex) { | |||
120 | unregister_code(hex_to_keycode(digit)); | 122 | unregister_code(hex_to_keycode(digit)); |
121 | } | 123 | } |
122 | } | 124 | } |
125 | |||
126 | void send_unicode_hex_string(const char *str) | ||
127 | { | ||
128 | if (!str) { return; } // Safety net | ||
129 | |||
130 | while (*str) { | ||
131 | // Find the next code point (token) in the string | ||
132 | for (; *str == ' '; str++); | ||
133 | size_t n = strcspn(str, " "); // Length of the current token | ||
134 | char code_point[n+1]; | ||
135 | strncpy(code_point, str, n); | ||
136 | code_point[n] = '\0'; // Make sure it's null-terminated | ||
137 | |||
138 | // Normalize the code point: make all hex digits lowercase | ||
139 | for (char *p = code_point; *p; p++) { | ||
140 | *p = tolower((unsigned char)*p); | ||
141 | } | ||
142 | |||
143 | // Send the code point as a Unicode input string | ||
144 | unicode_input_start(); | ||
145 | send_string(code_point); | ||
146 | unicode_input_finish(); | ||
147 | |||
148 | str += n; // Move to the first ' ' (or '\0') after the current token | ||
149 | } | ||
150 | } | ||
diff --git a/quantum/process_keycode/process_unicode_common.h b/quantum/process_keycode/process_unicode_common.h index 4d2b04fb3..814b60c57 100644 --- a/quantum/process_keycode/process_unicode_common.h +++ b/quantum/process_keycode/process_unicode_common.h | |||
@@ -31,6 +31,7 @@ uint8_t get_unicode_input_mode(void); | |||
31 | void unicode_input_start(void); | 31 | void unicode_input_start(void); |
32 | void unicode_input_finish(void); | 32 | void unicode_input_finish(void); |
33 | void register_hex(uint16_t hex); | 33 | void register_hex(uint16_t hex); |
34 | void send_unicode_hex_string(const char *str); | ||
34 | 35 | ||
35 | #define UC_OSX 0 // Mac OS X | 36 | #define UC_OSX 0 // Mac OS X |
36 | #define UC_LNX 1 // Linux | 37 | #define UC_LNX 1 // Linux |