sendKeys.ino 13 KB

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