diff options
Diffstat (limited to 'quantum/process_keycode/process_unicode.c')
| -rw-r--r-- | quantum/process_keycode/process_unicode.c | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/quantum/process_keycode/process_unicode.c b/quantum/process_keycode/process_unicode.c new file mode 100644 index 000000000..ad5d7f86b --- /dev/null +++ b/quantum/process_keycode/process_unicode.c | |||
| @@ -0,0 +1,57 @@ | |||
| 1 | #include "process_unicode.h" | ||
| 2 | |||
| 3 | static uint8_t input_mode; | ||
| 4 | |||
| 5 | uint16_t hex_to_keycode(uint8_t hex) | ||
| 6 | { | ||
| 7 | if (hex == 0x0) { | ||
| 8 | return KC_0; | ||
| 9 | } else if (hex < 0xA) { | ||
| 10 | return KC_1 + (hex - 0x1); | ||
| 11 | } else { | ||
| 12 | return KC_A + (hex - 0xA); | ||
| 13 | } | ||
| 14 | } | ||
| 15 | |||
| 16 | void set_unicode_mode(uint8_t os_target) | ||
| 17 | { | ||
| 18 | input_mode = os_target; | ||
| 19 | } | ||
| 20 | |||
| 21 | bool process_unicode(uint16_t keycode, keyrecord_t *record) { | ||
| 22 | if (keycode > QK_UNICODE && record->event.pressed) { | ||
| 23 | uint16_t unicode = keycode & 0x7FFF; | ||
| 24 | switch(input_mode) { | ||
| 25 | case UC_OSX: | ||
| 26 | register_code(KC_LALT); | ||
| 27 | break; | ||
| 28 | case UC_LNX: | ||
| 29 | register_code(KC_LCTL); | ||
| 30 | register_code(KC_LSFT); | ||
| 31 | register_code(KC_U); | ||
| 32 | unregister_code(KC_U); | ||
| 33 | break; | ||
| 34 | case UC_WIN: | ||
| 35 | register_code(KC_LALT); | ||
| 36 | register_code(KC_PPLS); | ||
| 37 | unregister_code(KC_PPLS); | ||
| 38 | break; | ||
| 39 | } | ||
| 40 | for(int i = 3; i >= 0; i--) { | ||
| 41 | uint8_t digit = ((unicode >> (i*4)) & 0xF); | ||
| 42 | register_code(hex_to_keycode(digit)); | ||
| 43 | unregister_code(hex_to_keycode(digit)); | ||
| 44 | } | ||
| 45 | switch(input_mode) { | ||
| 46 | case UC_OSX: | ||
| 47 | case UC_WIN: | ||
| 48 | unregister_code(KC_LALT); | ||
| 49 | break; | ||
| 50 | case UC_LNX: | ||
| 51 | unregister_code(KC_LCTL); | ||
| 52 | unregister_code(KC_LSFT); | ||
| 53 | break; | ||
| 54 | } | ||
| 55 | } | ||
| 56 | return true; | ||
| 57 | } \ No newline at end of file | ||
