sendKeys.ino 14 KB

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