1 #include "process_unicode.h"
2 #include "action_util.h"
4 static uint8_t input_mode;
7 void set_unicode_input_mode(uint8_t os_target)
9 input_mode = os_target;
12 uint8_t get_unicode_input_mode(void) {
17 void unicode_input_start (void) {
19 mods = keyboard_report->mods;
21 // unregister all mods to start from clean state
22 if (mods & MOD_BIT(KC_LSFT)) unregister_code(KC_LSFT);
23 if (mods & MOD_BIT(KC_RSFT)) unregister_code(KC_RSFT);
24 if (mods & MOD_BIT(KC_LCTL)) unregister_code(KC_LCTL);
25 if (mods & MOD_BIT(KC_RCTL)) unregister_code(KC_RCTL);
26 if (mods & MOD_BIT(KC_LALT)) unregister_code(KC_LALT);
27 if (mods & MOD_BIT(KC_RALT)) unregister_code(KC_RALT);
28 if (mods & MOD_BIT(KC_LGUI)) unregister_code(KC_LGUI);
29 if (mods & MOD_BIT(KC_RGUI)) unregister_code(KC_RGUI);
33 register_code(KC_LALT);
36 register_code(KC_LCTL);
37 register_code(KC_LSFT);
39 unregister_code(KC_U);
40 unregister_code(KC_LSFT);
41 unregister_code(KC_LCTL);
44 register_code(KC_LALT);
45 register_code(KC_PPLS);
46 unregister_code(KC_PPLS);
49 register_code(KC_RALT);
50 unregister_code(KC_RALT);
52 unregister_code(KC_U);
54 wait_ms(UNICODE_TYPE_DELAY);
58 void unicode_input_finish (void) {
62 unregister_code(KC_LALT);
65 register_code(KC_SPC);
66 unregister_code(KC_SPC);
70 // reregister previously set mods
71 if (mods & MOD_BIT(KC_LSFT)) register_code(KC_LSFT);
72 if (mods & MOD_BIT(KC_RSFT)) register_code(KC_RSFT);
73 if (mods & MOD_BIT(KC_LCTL)) register_code(KC_LCTL);
74 if (mods & MOD_BIT(KC_RCTL)) register_code(KC_RCTL);
75 if (mods & MOD_BIT(KC_LALT)) register_code(KC_LALT);
76 if (mods & MOD_BIT(KC_RALT)) register_code(KC_RALT);
77 if (mods & MOD_BIT(KC_LGUI)) register_code(KC_LGUI);
78 if (mods & MOD_BIT(KC_RGUI)) register_code(KC_RGUI);
81 void register_hex(uint16_t hex) {
82 for(int i = 3; i >= 0; i--) {
83 uint8_t digit = ((hex >> (i*4)) & 0xF);
84 register_code(hex_to_keycode(digit));
85 unregister_code(hex_to_keycode(digit));
89 bool process_unicode(uint16_t keycode, keyrecord_t *record) {
90 if (keycode > QK_UNICODE && record->event.pressed) {
91 uint16_t unicode = keycode & 0x7FFF;
92 unicode_input_start();
93 register_hex(unicode);
94 unicode_input_finish();