Add send_unicode_hex_string function (#3828)
* Add send_string_unicode function Co-authored-by: kdb424 <kdb424@gmail.com> Co-authored-by: Konstantin <vomindoraan@gmail.com> * Clean up code based on feedback * Fix includesmaster
parent
26f4e7031a
commit
f5ae3760c6
|
@ -19,7 +19,7 @@ table.
|
||||||
TBD
|
TBD
|
||||||
|
|
||||||
Unicode input in QMK works by inputing a sequence of characters to the OS,
|
Unicode input in QMK works by inputing a sequence of characters to the OS,
|
||||||
sort of like macro. Unfortunately, each OS has different ideas on how Unicode is inputted.
|
sort of like macro. Unfortunately, each OS has different ideas on how Unicode is input.
|
||||||
|
|
||||||
This is the current list of Unicode input method in QMK:
|
This is the current list of Unicode input method in QMK:
|
||||||
|
|
||||||
|
@ -29,6 +29,11 @@ This is the current list of Unicode input method in QMK:
|
||||||
* 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.
|
* 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.
|
||||||
* UC_WINC: Windows Unicode input using WinCompose. Requires [WinCompose](https://github.com/samhocevar/wincompose). Works reliably under many (all?) variations of Windows.
|
* UC_WINC: Windows Unicode input using WinCompose. Requires [WinCompose](https://github.com/samhocevar/wincompose). Works reliably under many (all?) variations of Windows.
|
||||||
|
|
||||||
|
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.
|
||||||
|
For example, the table flip seen above would be `send_unicode_hex_string("0028 30CE 0CA0 75CA 0CA0 0029 30CE 5F61 253B 2501 253B")`
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
# Additional Language Support
|
# Additional Language Support
|
||||||
|
|
||||||
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.
|
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.
|
||||||
|
|
|
@ -16,6 +16,8 @@
|
||||||
|
|
||||||
#include "process_unicode_common.h"
|
#include "process_unicode_common.h"
|
||||||
#include "eeprom.h"
|
#include "eeprom.h"
|
||||||
|
#include <string.h>
|
||||||
|
#include <ctype.h>
|
||||||
|
|
||||||
static uint8_t input_mode;
|
static uint8_t input_mode;
|
||||||
uint8_t mods;
|
uint8_t mods;
|
||||||
|
@ -120,3 +122,29 @@ void register_hex(uint16_t hex) {
|
||||||
unregister_code(hex_to_keycode(digit));
|
unregister_code(hex_to_keycode(digit));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void send_unicode_hex_string(const char *str)
|
||||||
|
{
|
||||||
|
if (!str) { return; } // Safety net
|
||||||
|
|
||||||
|
while (*str) {
|
||||||
|
// Find the next code point (token) in the string
|
||||||
|
for (; *str == ' '; str++);
|
||||||
|
size_t n = strcspn(str, " "); // Length of the current token
|
||||||
|
char code_point[n+1];
|
||||||
|
strncpy(code_point, str, n);
|
||||||
|
code_point[n] = '\0'; // Make sure it's null-terminated
|
||||||
|
|
||||||
|
// Normalize the code point: make all hex digits lowercase
|
||||||
|
for (char *p = code_point; *p; p++) {
|
||||||
|
*p = tolower((unsigned char)*p);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Send the code point as a Unicode input string
|
||||||
|
unicode_input_start();
|
||||||
|
send_string(code_point);
|
||||||
|
unicode_input_finish();
|
||||||
|
|
||||||
|
str += n; // Move to the first ' ' (or '\0') after the current token
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -31,6 +31,7 @@ uint8_t get_unicode_input_mode(void);
|
||||||
void unicode_input_start(void);
|
void unicode_input_start(void);
|
||||||
void unicode_input_finish(void);
|
void unicode_input_finish(void);
|
||||||
void register_hex(uint16_t hex);
|
void register_hex(uint16_t hex);
|
||||||
|
void send_unicode_hex_string(const char *str);
|
||||||
|
|
||||||
#define UC_OSX 0 // Mac OS X
|
#define UC_OSX 0 // Mac OS X
|
||||||
#define UC_LNX 1 // Linux
|
#define UC_LNX 1 // Linux
|
||||||
|
|
Loading…
Reference in New Issue