sendKeys.ino 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508
  1. void printKey() {
  2. if (useSerial) {
  3. Serial.print(F("KEY_"));
  4. }
  5. }
  6. void printMedia() {
  7. if (useSerial) {
  8. Serial.print(F("MEDIA_"));
  9. }
  10. }
  11. void printArrow() {
  12. if (useSerial) {
  13. Serial.print(F("ARROW_"));
  14. }
  15. }
  16. void sendKey(uint8_t _key) {
  17. if(debug) Serial.println(F("SENDING KEY"));
  18. switch (_key) {
  19. // case BTN_POWER:
  20. // //handlePowerButton();
  21. // if (useSerial) {
  22. // printKey();
  23. // Serial.println(F("POWER"));
  24. // }
  25. // break;
  26. case BTN_OK_ENTER:
  27. if (sendHID) BootKeyboard.write(KEY_ENTER);
  28. if (useSerial) {
  29. printKey();
  30. Serial.println(F("OK_ENTER"));
  31. }
  32. break;
  33. case BTN_UP:
  34. if (sendHID) BootKeyboard.write(KEY_UP_ARROW);
  35. if (useSerial) {
  36. printKey();
  37. Serial.println(F("UP"));
  38. }
  39. handleTaskSwitchButton_extendAltTabTimeout();
  40. break;
  41. case BTN_DOWN:
  42. if (sendHID) BootKeyboard.write(KEY_DOWN_ARROW);
  43. if (useSerial) {
  44. printKey();
  45. Serial.println(F("DOWN"));
  46. }
  47. handleTaskSwitchButton_extendAltTabTimeout();
  48. break;
  49. case BTN_RIGHT:
  50. if (sendHID) BootKeyboard.write(KEY_RIGHT_ARROW);
  51. if (useSerial) {
  52. printKey();
  53. Serial.println(F("RIGHT"));
  54. }
  55. handleTaskSwitchButton_extendAltTabTimeout();
  56. break;
  57. case BTN_LEFT:
  58. if (sendHID) BootKeyboard.write(KEY_LEFT_ARROW);
  59. if (useSerial) {
  60. printKey();
  61. Serial.println(F("LEFT"));
  62. }
  63. handleTaskSwitchButton_extendAltTabTimeout();
  64. break;
  65. case BTN_PLAY:
  66. if (sendHID) Consumer.write(MEDIA_PLAY_PAUSE);
  67. if (useSerial) {
  68. printKey();
  69. printMedia();
  70. Serial.println(F("PLAY"));
  71. }
  72. break;
  73. case BTN_PAUSE:
  74. if (sendHID) Consumer.write(MEDIA_PLAY_PAUSE);
  75. if (useSerial) {
  76. printKey();
  77. printMedia();
  78. Serial.println(F("PAUSE"));
  79. }
  80. break;
  81. case BTN_STOP:
  82. if (sendHID) Consumer.write(MEDIA_STOP);
  83. if (useSerial) {
  84. printKey();
  85. printMedia();
  86. Serial.println(F("STOP"));
  87. }
  88. break;
  89. case BTN_REC:
  90. if (useSerial) {
  91. printKey();
  92. Serial.println(F("REC"));
  93. }
  94. break;
  95. case BTN_REWD:
  96. if (sendHID) Consumer.write(MEDIA_REWIND);
  97. if (useSerial) {
  98. printKey();
  99. printMedia();
  100. Serial.println(F("REWD"));
  101. }
  102. break;
  103. case BTN_FFWD:
  104. if (sendHID) Consumer.write(MEDIA_FAST_FORWARD);
  105. if (useSerial) {
  106. printKey();
  107. printMedia();
  108. Serial.println(F("FFWD"));
  109. }
  110. break;
  111. case BTN_PREV:
  112. if (sendHID) Consumer.write(MEDIA_PREVIOUS);
  113. if (useSerial) {
  114. printKey();
  115. printMedia();
  116. Serial.println(F("PREV"));
  117. }
  118. break;
  119. case BTN_NEXT:
  120. if (sendHID) Consumer.write(MEDIA_NEXT);
  121. if (useSerial) {
  122. printKey();
  123. printMedia();
  124. Serial.println(F("NEXT"));
  125. }
  126. break;
  127. case BTN_BACK:
  128. if (sendHID) BootKeyboard.write(KEY_BACKSPACE);
  129. if (useSerial) {
  130. printKey();
  131. Serial.println(F("BACK"));
  132. }
  133. break;
  134. case BTN_MENU:
  135. if (sendHID) BootKeyboard.write(KEY_ESC);
  136. if (useSerial) {
  137. printKey();
  138. Serial.println(F("MENU"));
  139. }
  140. break;
  141. case BTN_HOME:
  142. if (sendHID) BootKeyboard.write(KEY_LEFT_WINDOWS);
  143. if (useSerial) {
  144. printKey();
  145. Serial.println(F("HOME"));
  146. }
  147. break;
  148. case BTN_RED:
  149. if (sendHID) {
  150. BootKeyboard.press(KEY_LEFT_CTRL);
  151. BootKeyboard.press(KEY_LEFT_ALT);
  152. BootKeyboard.press(KEY_LEFT_WINDOWS);
  153. BootKeyboard.press(KEY_F7);
  154. delay(50);
  155. BootKeyboard.releaseAll();
  156. }
  157. if (useSerial) {
  158. printKey();
  159. Serial.println(F("RED"));
  160. Serial.println("sending CTRL+ALT+WIN+F7");
  161. }
  162. break;
  163. case BTN_GREEN:
  164. if (sendHID) {
  165. BootKeyboard.press(KEY_LEFT_CTRL);
  166. BootKeyboard.press(KEY_LEFT_ALT);
  167. BootKeyboard.press(KEY_LEFT_WINDOWS);
  168. BootKeyboard.press(KEY_F8);
  169. delay(50);
  170. BootKeyboard.releaseAll();
  171. }
  172. if (useSerial) {
  173. printKey();
  174. Serial.println(F("GREEN"));
  175. Serial.println(F("sending CTRL+ALT+WIN+F8"));
  176. }
  177. break;
  178. case BTN_YELLOW:
  179. if (sendHID) {
  180. BootKeyboard.press(KEY_LEFT_CTRL);
  181. BootKeyboard.press(KEY_LEFT_ALT);
  182. BootKeyboard.press(KEY_LEFT_WINDOWS);
  183. BootKeyboard.press(KEY_F9);
  184. delay(50);
  185. BootKeyboard.releaseAll();
  186. }
  187. if (useSerial) {
  188. printKey();
  189. Serial.println(F("YELLOW"));
  190. Serial.println(F("sending CTRL+ALT+WIN+F9"));
  191. }
  192. break;
  193. case BTN_BLUE:
  194. if (sendHID) {
  195. BootKeyboard.press(KEY_LEFT_CTRL);
  196. BootKeyboard.press(KEY_LEFT_ALT);
  197. BootKeyboard.press(KEY_LEFT_WINDOWS);
  198. BootKeyboard.press(KEY_F10);
  199. delay(50);
  200. BootKeyboard.releaseAll();
  201. }
  202. if (useSerial) {
  203. printKey();
  204. Serial.println(F("BLUE"));
  205. Serial.println("sending CTRL+ALT+WIN+F10");
  206. }
  207. break;
  208. case BTN_STATUS:
  209. if (useSerial) {
  210. printKey();
  211. Serial.println(F("STATUS"));
  212. }
  213. break;
  214. case BTN_RETURN:
  215. if (useSerial) {
  216. printKey();
  217. Serial.println(F("RETURN"));
  218. }
  219. break;
  220. case BTN_SETUP:
  221. if (useSerial) {
  222. printKey();
  223. Serial.println(F("SETUP"));
  224. }
  225. break;
  226. case BTN_GUIDE:
  227. if (sendHID) {
  228. BootKeyboard.press(KEY_LEFT_CTRL);
  229. delay(2);
  230. BootKeyboard.press(KEY_LEFT_ALT);
  231. delay(2);
  232. BootKeyboard.press(KEY_LEFT_WINDOWS);
  233. delay(2);
  234. BootKeyboard.press(KEY_F5);
  235. delay(20);
  236. BootKeyboard.releaseAll();
  237. }
  238. if (useSerial) {
  239. printKey();
  240. Serial.println(F("GUIDE"));
  241. Serial.println(F("sending CTRL+ALT+WIN+F5"));
  242. }
  243. break;
  244. case BTN_RADIO:
  245. if (sendHID) {
  246. BootKeyboard.press(KEY_LEFT_CTRL);
  247. delay(2);
  248. BootKeyboard.press(KEY_LEFT_ALT);
  249. delay(2);
  250. BootKeyboard.press(KEY_LEFT_WINDOWS);
  251. delay(2);
  252. BootKeyboard.press(KEY_F6);
  253. delay(20);
  254. BootKeyboard.releaseAll();
  255. }
  256. if (useSerial) {
  257. printKey();
  258. Serial.println(F("RADIO"));
  259. Serial.println(F("sending CTRL+ALT+WIN+F6"));
  260. }
  261. break;
  262. case BTN_PREVCH:
  263. if (useSerial) {
  264. printKey();
  265. Serial.println(F("PREVCH"));
  266. }
  267. break;
  268. case BTN_CONTEXT:
  269. if (useSerial) {
  270. printKey();
  271. Serial.println(F("CONTEXT"));
  272. }
  273. BootKeyboard.write(KEY_C);
  274. break;
  275. case BTN_INFO:
  276. if (useSerial) {
  277. printKey();
  278. Serial.println(F("INFO"));
  279. }
  280. BootKeyboard.write(KEY_I);
  281. break;
  282. case BTN_CH_DOWN:
  283. if (sendHID) {
  284. BootKeyboard.write(KEY_PAGE_DOWN);
  285. //BootKeyboard.releaseAll();
  286. }
  287. if (useSerial) {
  288. printKey();
  289. Serial.println(F("CH_DOWN"));
  290. }
  291. break;
  292. case BTN_CH_UP:
  293. if (sendHID) {
  294. BootKeyboard.write(KEY_PAGE_UP);
  295. //BootKeyboard.releaseAll();
  296. }
  297. if (useSerial) {
  298. printKey();
  299. Serial.println(F("CH_UP"));
  300. }
  301. break;
  302. case BTN_PAGE_DOWN:
  303. if (sendHID) {
  304. BootKeyboard.write(KEY_PAGE_DOWN);
  305. //BootKeyboard.releaseAll();
  306. }
  307. if (useSerial) {
  308. printKey();
  309. Serial.println(F("PAGE_DOWN"));
  310. }
  311. break;
  312. case BTN_PAGE_UP:
  313. if (sendHID) {
  314. BootKeyboard.write(KEY_PAGE_UP);
  315. //BootKeyboard.releaseAll();
  316. }
  317. if (useSerial) {
  318. printKey();
  319. Serial.println(F("PAGE_UP"));
  320. }
  321. break;
  322. case BTN_VOL_DOWN:
  323. if (sendHID) Consumer.write(MEDIA_VOLUME_DOWN);
  324. if (useSerial) {
  325. printKey();
  326. printMedia();
  327. Serial.println(F("VOLUME_DOWN"));
  328. }
  329. break;
  330. case BTN_VOL_UP:
  331. if (sendHID) Consumer.write(MEDIA_VOLUME_UP);
  332. if (useSerial) {
  333. printKey();
  334. printMedia();
  335. Serial.println(F("VOLUME_UP"));
  336. }
  337. break;
  338. case BTN_MUTE:
  339. if (sendHID) Consumer.write(MEDIA_VOLUME_MUTE);
  340. if (useSerial) {
  341. printKey();
  342. printMedia();
  343. Serial.println(F("VOLUME_MUTE"));
  344. }
  345. break;
  346. case BTN_TV:
  347. if (sendHID) {
  348. BootKeyboard.press(KEY_LEFT_CTRL);
  349. delay(2);
  350. BootKeyboard.press(KEY_LEFT_WINDOWS);
  351. delay(2);
  352. BootKeyboard.press(KEY_LEFT_ALT);
  353. delay(2);
  354. BootKeyboard.press(KEY_F1);
  355. delay(20);
  356. BootKeyboard.releaseAll();
  357. }
  358. if (useSerial) {
  359. printKey();
  360. Serial.println(F("TV"));
  361. Serial.println(F("sending CTRL+ALT+WIN+F1"));
  362. }
  363. break;
  364. case BTN_VIDEOS:
  365. if (sendHID) {
  366. BootKeyboard.press(KEY_LEFT_CTRL);
  367. delay(2);
  368. BootKeyboard.press(KEY_LEFT_ALT);
  369. delay(2);
  370. BootKeyboard.press(KEY_LEFT_WINDOWS);
  371. delay(2);
  372. BootKeyboard.press(KEY_F2);
  373. delay(20);
  374. BootKeyboard.releaseAll();
  375. }
  376. if (useSerial) {
  377. printKey();
  378. Serial.println(F("VIDEOS"));
  379. Serial.println(F("sending CTRL+ALT+WIN+F2"));
  380. }
  381. break;
  382. case BTN_MUSIC:
  383. if (sendHID) {
  384. BootKeyboard.press(KEY_LEFT_CTRL);
  385. delay(2);
  386. BootKeyboard.press(KEY_LEFT_ALT);
  387. delay(2);
  388. BootKeyboard.press(KEY_LEFT_WINDOWS);
  389. delay(2);
  390. BootKeyboard.press(KEY_F3);
  391. delay(20);
  392. BootKeyboard.releaseAll();
  393. }
  394. if (useSerial) {
  395. printKey();
  396. Serial.println(F("MUSIC"));
  397. Serial.println(F("sending CTRL+ALT+WIN+F3"));
  398. }
  399. break;
  400. case BTN_PICTURES:
  401. if (sendHID) {
  402. BootKeyboard.press(KEY_LEFT_CTRL);
  403. delay(2);
  404. BootKeyboard.press(KEY_LEFT_WINDOWS);
  405. delay(2);
  406. BootKeyboard.press(KEY_LEFT_ALT);
  407. delay(2);
  408. BootKeyboard.press(KEY_F4);
  409. delay(20);
  410. BootKeyboard.releaseAll();
  411. }
  412. if (useSerial) {
  413. printKey();
  414. Serial.println(F("PICTURES"));
  415. Serial.println(F("sending CTRL+ALT+WIN+F4"));
  416. }
  417. break;
  418. case BTN_STAR:
  419. if (useSerial) {
  420. printKey();
  421. Serial.println(F("STAR"));
  422. }
  423. break;
  424. case BTN_HASH:
  425. if (useSerial) {
  426. printKey();
  427. Serial.println(F("HASH"));
  428. }
  429. break;
  430. case BTN_0:
  431. if (sendHID) BootKeyboard.write('0');
  432. if (useSerial) {
  433. printKey();
  434. Serial.println("0");
  435. }
  436. break;
  437. case BTN_1:
  438. if (sendHID) BootKeyboard.write('1');
  439. if (useSerial) {
  440. printKey();
  441. Serial.println("1");
  442. }
  443. break;
  444. case BTN_2:
  445. if (sendHID) BootKeyboard.write('2');
  446. if (useSerial) {
  447. printKey();
  448. Serial.println("2");
  449. }
  450. break;
  451. case BTN_3:
  452. if (sendHID) BootKeyboard.write('3');
  453. if (useSerial) {
  454. printKey();
  455. Serial.println("3");
  456. }
  457. break;
  458. case BTN_4:
  459. if (sendHID) BootKeyboard.write('4');
  460. if (useSerial) {
  461. printKey();
  462. Serial.println("4");
  463. }
  464. break;
  465. case BTN_5:
  466. if (sendHID) BootKeyboard.write('5');
  467. if (useSerial) {
  468. printKey();
  469. Serial.println("5");
  470. }
  471. break;
  472. case BTN_6:
  473. if (sendHID) BootKeyboard.write('6');
  474. if (useSerial) {
  475. printKey();
  476. Serial.println("6");
  477. }
  478. break;
  479. case BTN_7:
  480. if (sendHID) BootKeyboard.write('7');
  481. if (useSerial) {
  482. printKey();
  483. Serial.println("7");
  484. }
  485. break;
  486. case BTN_8:
  487. if (sendHID) BootKeyboard.write('8');
  488. if (useSerial) {
  489. printKey();
  490. Serial.println("8");
  491. }
  492. break;
  493. case BTN_9:
  494. if (sendHID) BootKeyboard.write('9');
  495. if (useSerial) {
  496. printKey();
  497. Serial.println("9");
  498. }
  499. break;
  500. }
  501. }