From e696e4c152816e661fb6ea7c1c9a6affe410055f Mon Sep 17 00:00:00 2001 From: Jack Humbert Date: Sun, 24 Jan 2016 21:05:03 -0500 Subject: unicode working --- quantum/keymap_unicode.c | 49 +++++++++++++++++++++++++----------------------- 1 file changed, 26 insertions(+), 23 deletions(-) (limited to 'quantum/keymap_unicode.c') diff --git a/quantum/keymap_unicode.c b/quantum/keymap_unicode.c index 3a480878b7..cda167d2c1 100644 --- a/quantum/keymap_unicode.c +++ b/quantum/keymap_unicode.c @@ -16,6 +16,9 @@ along with this program. If not, see . */ #include "keymap_common.h" +#include + +#define UNICODE_OSX /* Mac with Unicode Hex Input */ uint16_t hextokeycode(int hex) { if (hex == 0x0) { @@ -29,33 +32,33 @@ uint16_t hextokeycode(int hex) { void action_custom(keyrecord_t *record, uint32_t code) { - // For more info on how this works per OS, see here: https://en.wikipedia.org/wiki/Unicode_input#Hexadecimal_code_input if (record->event.pressed) { + #ifdef UNICODE_OSX + register_code(KC_LALT); + #endif + uint32_t unicode = code; - // register_code(KC_LALT); - - register_code(hextokeycode((unicode & 0xF000) >> 12)); - unregister_code(hextokeycode((unicode & 0xF000) >> 12)); - register_code(hextokeycode((unicode & 0x0F00) >> 8)); - unregister_code(hextokeycode((unicode & 0x0F00) >> 8)); - register_code(hextokeycode((unicode & 0x00F0) >> 4)); - unregister_code(hextokeycode((unicode & 0x00F0) >> 4)); - register_code(hextokeycode((unicode & 0x000F))); - unregister_code(hextokeycode((unicode & 0x000F))); - - /* Test 'a' */ - // register_code(hextokeycode(0x0)); - // unregister_code(hextokeycode(0x0)); - // register_code(hextokeycode(0x0)); - // unregister_code(hextokeycode(0x0)); - // register_code(hextokeycode(0x6)); - // unregister_code(hextokeycode(0x6)); - // register_code(hextokeycode(0x1)); - // unregister_code(hextokeycode(0x1)); - - // unregister_code(KC_LALT); + bool leading_zero = false; + for(int i = 6; i >= 0; i--) { + uint8_t digit = ((unicode >> (int)(i*4)) & 0xF); + if (digit > 0 || leading_zero || (i < 4)) { + leading_zero = true; + register_code(hextokeycode(digit)); + unregister_code(hextokeycode(digit)); + if (i == 4) { + register_code(KC_LSFT); + register_code(KC_EQL); + unregister_code(KC_EQL); + unregister_code(KC_LSFT); + } + } + } + + #ifdef UNICODE_OSX + unregister_code(KC_LALT); + #endif } return; } \ No newline at end of file -- cgit v1.2.3