keymap_unicode.c 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*
  2. Copyright 2015 Jack Humbert <jack.humb@gmail.com>
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation, either version 2 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. */
  14. #include "keymap_common.h"
  15. uint16_t hextokeycode(int hex) {
  16. if (hex == 0x0) {
  17. return KC_0;
  18. } else if (hex < 0xA) {
  19. return KC_1 + (hex - 0x1);
  20. } else {
  21. return KC_A + (hex - 0xA);
  22. }
  23. }
  24. void action_function(keyrecord_t *record, uint8_t id, uint8_t opt)
  25. {
  26. // For more info on how this works per OS, see here: https://en.wikipedia.org/wiki/Unicode_input#Hexadecimal_code_input
  27. if (record->event.pressed) {
  28. uint16_t unicode = (opt << 8) | id;
  29. register_code(KC_LALT);
  30. register_code(hextokeycode((unicode & 0xF000) >> 12));
  31. unregister_code(hextokeycode((unicode & 0xF000) >> 12));
  32. register_code(hextokeycode((unicode & 0x0F00) >> 8));
  33. unregister_code(hextokeycode((unicode & 0x0F00) >> 8));
  34. register_code(hextokeycode((unicode & 0x00F0) >> 4));
  35. unregister_code(hextokeycode((unicode & 0x00F0) >> 4));
  36. register_code(hextokeycode((unicode & 0x000F)));
  37. unregister_code(hextokeycode((unicode & 0x000F)));
  38. /* Test 'a' */
  39. // register_code(hextokeycode(0x0));
  40. // unregister_code(hextokeycode(0x0));
  41. // register_code(hextokeycode(0x0));
  42. // unregister_code(hextokeycode(0x0));
  43. // register_code(hextokeycode(0x6));
  44. // unregister_code(hextokeycode(0x6));
  45. // register_code(hextokeycode(0x1));
  46. // unregister_code(hextokeycode(0x1));
  47. unregister_code(KC_LALT);
  48. }
  49. return;
  50. }