diff --git a/examples/Unicode/Unicode.ino b/examples/Unicode/Unicode.ino index 89362015..9fd4416d 100644 --- a/examples/Unicode/Unicode.ino +++ b/examples/Unicode/Unicode.ino @@ -24,33 +24,33 @@ #include const Key keymaps[][ROWS][COLS] PROGMEM = { - [0] = KEYMAP_STACKED - ( - Key_NoKey, Key_1, Key_2, Key_3, Key_4, Key_5, Key_NoKey, - Key_Backtick, Key_Q, Key_W, Key_E, Key_R, Key_T, Key_Tab, - Key_PageUp, Key_A, Key_S, Key_D, Key_F, Key_G, - Key_PageDown, Key_Z, Key_X, Key_C, Key_V, Key_B, Key_Escape, - - Key_LeftControl, Key_Backspace, Key_LeftGui, Key_LeftShift, - Key_skip, - - Key_skip, Key_6, Key_7, Key_8, Key_9, Key_0, Key_skip, - Key_Enter, Key_Y, Key_U, Key_I, Key_O, Key_P, Key_Equals, - Key_H, Key_J, Key_K, Key_L, Key_Semicolon, Key_Quote, - Key_skip, Key_N, Key_M, Key_Comma, Key_Period, Key_Slash, Key_Minus, - - Key_RightShift, Key_RightAlt, Key_Spacebar, Key_RightControl, - Key_skip - ), + [0] = KEYMAP_STACKED + ( + Key_NoKey, Key_1, Key_2, Key_3, Key_4, Key_5, Key_NoKey, + Key_Backtick, Key_Q, Key_W, Key_E, Key_R, Key_T, Key_Tab, + Key_PageUp, Key_A, Key_S, Key_D, Key_F, Key_G, + Key_PageDown, Key_Z, Key_X, Key_C, Key_V, Key_B, Key_Escape, + + Key_LeftControl, Key_Backspace, Key_LeftGui, Key_LeftShift, + Key_skip, + + Key_skip, Key_6, Key_7, Key_8, Key_9, Key_0, Key_skip, + Key_Enter, Key_Y, Key_U, Key_I, Key_O, Key_P, Key_Equals, + Key_H, Key_J, Key_K, Key_L, Key_Semicolon, Key_Quote, + Key_skip, Key_N, Key_M, Key_Comma, Key_Period, Key_Slash, Key_Minus, + + Key_RightShift, Key_RightAlt, Key_Spacebar, Key_RightControl, + Key_skip + ), }; void setup () { - Kaleidoscope.setup (KEYMAP_SIZE); - Kaleidoscope.use (&HostOS, &Unicode, NULL); + Kaleidoscope.setup (KEYMAP_SIZE); + Kaleidoscope.use (&HostOS, &Unicode, NULL); - Unicode.type (0x2328); + Unicode.type (0x2328); } void loop () { - Kaleidoscope.loop (); + Kaleidoscope.loop (); } diff --git a/src/Kaleidoscope/Unicode.cpp b/src/Kaleidoscope/Unicode.cpp index 4f169c2d..ad4e73b0 100644 --- a/src/Kaleidoscope/Unicode.cpp +++ b/src/Kaleidoscope/Unicode.cpp @@ -20,144 +20,144 @@ namespace KaleidoscopePlugins { - Unicode::Unicode (void) { - } +Unicode::Unicode (void) { +} - void - Unicode::begin (void) { +void +Unicode::begin (void) { ::HostOS.begin (); - } +} - void - Unicode::start (void) { +void +Unicode::start (void) { switch (::HostOS.os ()) { case HostOS::LINUX: - Keyboard.press (Key_LeftControl.keyCode); - Keyboard.press (Key_LeftShift.keyCode); - Keyboard.press (Key_U.keyCode); - Keyboard.sendReport (); - Keyboard.release (Key_LeftControl.keyCode); - Keyboard.release (Key_LeftShift.keyCode); - Keyboard.release (Key_U.keyCode); - Keyboard.sendReport (); - break; + Keyboard.press (Key_LeftControl.keyCode); + Keyboard.press (Key_LeftShift.keyCode); + Keyboard.press (Key_U.keyCode); + Keyboard.sendReport (); + Keyboard.release (Key_LeftControl.keyCode); + Keyboard.release (Key_LeftShift.keyCode); + Keyboard.release (Key_U.keyCode); + Keyboard.sendReport (); + break; case HostOS::WINDOWS: - Keyboard.press (Key_RightAlt.keyCode); - Keyboard.sendReport (); - Keyboard.release (Key_RightAlt.keyCode); - Keyboard.sendReport (); - Keyboard.press (Key_U.keyCode); - Keyboard.sendReport (); - Keyboard.release (Key_U.keyCode); - Keyboard.sendReport (); - break; + Keyboard.press (Key_RightAlt.keyCode); + Keyboard.sendReport (); + Keyboard.release (Key_RightAlt.keyCode); + Keyboard.sendReport (); + Keyboard.press (Key_U.keyCode); + Keyboard.sendReport (); + Keyboard.release (Key_U.keyCode); + Keyboard.sendReport (); + break; case HostOS::OSX: - Keyboard.press (Key_LeftAlt.keyCode); - break; + Keyboard.press (Key_LeftAlt.keyCode); + break; default: - unicodeCustomStart (); - break; + unicodeCustomStart (); + break; } - } +} - void - Unicode::input (void) { +void +Unicode::input (void) { switch (::HostOS.os ()) { case HostOS::LINUX: case HostOS::WINDOWS: - break; + break; case HostOS::OSX: - Keyboard.press (Key_LeftAlt.keyCode); - break; + Keyboard.press (Key_LeftAlt.keyCode); + break; default: - unicodeCustomInput (); - break; + unicodeCustomInput (); + break; } - } +} - void - Unicode::end (void) { +void +Unicode::end (void) { switch (::HostOS.os ()) { case HostOS::LINUX: - Keyboard.press (Key_Spacebar.keyCode); - Keyboard.sendReport (); - Keyboard.release (Key_Spacebar.keyCode); - Keyboard.sendReport (); - break; + Keyboard.press (Key_Spacebar.keyCode); + Keyboard.sendReport (); + Keyboard.release (Key_Spacebar.keyCode); + Keyboard.sendReport (); + break; case HostOS::WINDOWS: - break; + break; case HostOS::OSX: - Keyboard.release (Key_LeftAlt.keyCode); - Keyboard.sendReport (); - break; + Keyboard.release (Key_LeftAlt.keyCode); + Keyboard.sendReport (); + break; default: - unicodeCustomEnd (); - break; + unicodeCustomEnd (); + break; } - } +} - void - Unicode::typeCode (uint32_t unicode) { +void +Unicode::typeCode (uint32_t unicode) { bool onZeroStart = true; for (int8_t i = 7; i >= 0; i--) { - if (i <= 3) { - onZeroStart = false; - } - - uint8_t digit = ((unicode >> (i * 4)) & 0xF); - if (digit == 0) { - if (onZeroStart == false) { - Key key = hexToKey (digit); - - input (); - Keyboard.press (key.keyCode); - Keyboard.sendReport (); - input (); - Keyboard.release (key.keyCode); - Keyboard.sendReport (); + if (i <= 3) { + onZeroStart = false; } - } else { - Key key = hexToKey (digit); - - input (); - Keyboard.press (key.keyCode); - Keyboard.sendReport (); - input (); - Keyboard.release (key.keyCode); - Keyboard.sendReport (); - onZeroStart = false; - } + uint8_t digit = ((unicode >> (i * 4)) & 0xF); + if (digit == 0) { + if (onZeroStart == false) { + Key key = hexToKey (digit); + + input (); + Keyboard.press (key.keyCode); + Keyboard.sendReport (); + input (); + Keyboard.release (key.keyCode); + Keyboard.sendReport (); + } + } else { + Key key = hexToKey (digit); + + input (); + Keyboard.press (key.keyCode); + Keyboard.sendReport (); + input (); + Keyboard.release (key.keyCode); + Keyboard.sendReport (); + + onZeroStart = false; + } - delay (5); + delay (5); } - } +} - void - Unicode::type (uint32_t unicode) { +void +Unicode::type (uint32_t unicode) { start (); typeCode (unicode); end (); - } +} }; __attribute__((weak)) Key hexToKey (uint8_t hex) { - uint8_t m; + uint8_t m; - if (hex == 0x0) { - return Key_0; - } + if (hex == 0x0) { + return Key_0; + } - if (hex < 0xA) { - m = Key_1.keyCode + (hex - 0x1); - } else { - m = Key_A.keyCode + (hex - 0xA); - } + if (hex < 0xA) { + m = Key_1.keyCode + (hex - 0x1); + } else { + m = Key_A.keyCode + (hex - 0xA); + } - return { m, KEY_FLAGS }; + return { m, KEY_FLAGS }; } __attribute__((weak)) diff --git a/src/Kaleidoscope/Unicode.h b/src/Kaleidoscope/Unicode.h index 71712b23..b3152211 100644 --- a/src/Kaleidoscope/Unicode.h +++ b/src/Kaleidoscope/Unicode.h @@ -22,7 +22,7 @@ #include namespace KaleidoscopePlugins { - class Unicode : public KaleidoscopePlugin { +class Unicode : public KaleidoscopePlugin { public: Unicode (void); @@ -34,7 +34,7 @@ namespace KaleidoscopePlugins { static void type (uint32_t unicode); static void typeCode (uint32_t unicode); - }; +}; }; Key hexToKey (uint8_t hex);