win-zh_util.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. Windows Chinese Typing Codec for Unicode and Big5
  3. This is a module that handle Traditional Chinese typing
  4. on Windows devices using ALT + utf-8 or big5 DEC code
  5. method. Note that this only works on computer with native
  6. Chinese support (Tested on Windows 10 Chinese version for
  7. Hong Kong and Taiwan).
  8. Primary design for CH552G, but in theory, should work with
  9. any Arduino board supporting USB HID keyboard.
  10. CopyRight tobychui, All Right Reserved
  11. */
  12. #include <Arduino.h>
  13. #include <string.h>
  14. void pressNumericAsKeypad(char in){
  15. int delayTime = 1;
  16. switch (in) {
  17. case '0':
  18. Keyboard_press('\352');
  19. delay(delayTime);
  20. Keyboard_release('\352');
  21. break;
  22. case '1':
  23. Keyboard_press('\341');
  24. delay(delayTime);
  25. Keyboard_release('\341');
  26. break;
  27. case '2':
  28. Keyboard_press('\342');
  29. delay(delayTime);
  30. Keyboard_release('\342');
  31. break;
  32. case '3':
  33. Keyboard_press('\343');
  34. delay(delayTime);
  35. Keyboard_release('\343');
  36. break;
  37. case '4':
  38. Keyboard_press('\344');
  39. delay(delayTime);
  40. Keyboard_release('\344');
  41. break;
  42. case '5':
  43. Keyboard_press('\345');
  44. delay(delayTime);
  45. Keyboard_release('\345');
  46. break;
  47. case '6':
  48. Keyboard_press('\346');
  49. delay(delayTime);
  50. Keyboard_release('\346');
  51. break;
  52. case '7':
  53. Keyboard_press('\347');
  54. delay(delayTime);
  55. Keyboard_release('\347');
  56. break;
  57. case '8':
  58. Keyboard_press('\350');
  59. delay(delayTime);
  60. Keyboard_release('\350');
  61. break;
  62. case '9':
  63. Keyboard_press('\351');
  64. delay(delayTime);
  65. Keyboard_release('\351');
  66. break;
  67. default:
  68. return;
  69. break;
  70. }
  71. }
  72. void typeChinese(char* keycode){
  73. //Hold ALT
  74. Keyboard_press(KEY_LEFT_ALT);
  75. delay(20);
  76. for (int i = 0; i < strlen(keycode); i++) {
  77. pressNumericAsKeypad(keycode[i]);
  78. }
  79. //Release ALT
  80. delay(20);
  81. Keyboard_release(KEY_LEFT_ALT);
  82. }