actions.ino 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. /*
  2. HANDLE KEY CHANGES
  3. The section below define what to do when a user pressed a key or release a key.
  4. The key layout is identical to the 2D array defined at the top of the main script.
  5. See that for more information
  6. */
  7. void HandleKeyPressEvents(int row, int col, bool previousState, bool currentState) {
  8. bool isKeyDown = (previousState == false && currentState == true);
  9. bool isKeyUp = (previousState == true && currentState == false);
  10. if (isKeyDown) {
  11. /*
  12. *
  13. * KEY DOWN EVENTS
  14. *
  15. * Toggle when the key is just pressed
  16. *
  17. */
  18. switch (row) {
  19. case 0:
  20. switch (col) {
  21. case 0:
  22. // Case: row 0, col 0
  23. Keyboard_press('\352'); //0
  24. break;
  25. case 1:
  26. // Case: row 0, col 1
  27. //Fn Key
  28. funcMode = true;
  29. break;
  30. case 2:
  31. // Case: row 0, col 2
  32. // Keypad .
  33. Keyboard_press('\353');
  34. break;
  35. case 3:
  36. // Case: row 0, col 3
  37. //Keypad Enter
  38. Keyboard_press('\340');
  39. break;
  40. }
  41. break;
  42. case 1:
  43. switch (col) {
  44. case 0:
  45. // Case: row 1, col 0
  46. Keyboard_press('\341'); //1
  47. break;
  48. case 1:
  49. // Case: row 1, col 1
  50. Keyboard_press('\342'); //2
  51. break;
  52. case 2:
  53. // Case: row 1, col 2
  54. Keyboard_press('\343'); //3
  55. break;
  56. case 3:
  57. // Case: row 1, col 3
  58. //keypad +
  59. Keyboard_press('\337');
  60. break;
  61. }
  62. break;
  63. case 2:
  64. // Cases for row 2 (col 0, col 1, col 2, col 3)
  65. switch (col) {
  66. case 0:
  67. // Case: row 2, col 0
  68. Keyboard_press('\344');
  69. break;
  70. case 1:
  71. // Case: row 2, col 1
  72. Keyboard_press('\345');
  73. break;
  74. case 2:
  75. // Case: row 2, col 2
  76. Keyboard_press('\346');
  77. break;
  78. case 3:
  79. // Case: row 2, col 3
  80. if (funcMode) {
  81. //Vol Down
  82. Consumer_write(MEDIA_VOLUME_DOWN);
  83. } else {
  84. //Previous Song
  85. Consumer_write(MEDIA_PREV);
  86. }
  87. break;
  88. }
  89. break;
  90. case 3:
  91. // Cases for row 3 (col 0, col 1, col 2, col 3)
  92. switch (col) {
  93. case 0:
  94. // Case: row 3, col 0
  95. Keyboard_press('\347'); //7
  96. break;
  97. case 1:
  98. // Case: row 3, col 1
  99. Keyboard_press('\350'); //8
  100. break;
  101. case 2:
  102. // Case: row 3, col 2
  103. Keyboard_press('\351'); //9
  104. break;
  105. case 3:
  106. // Case: row 3, col 3
  107. if (funcMode) {
  108. //Vol Up
  109. Consumer_write(MEDIA_VOLUME_UP);
  110. } else {
  111. //Next Song
  112. Consumer_write(MEDIA_NEXT);
  113. }
  114. break;
  115. }
  116. break;
  117. case 4:
  118. // Cases for row 4 (col 0, col 1, col 2, col 3)
  119. switch (col) {
  120. case 0:
  121. // Case: row 4, col 0
  122. //NUM LOCK
  123. Keyboard_press('\333');
  124. break;
  125. case 1:
  126. // Case: row 4, col 1
  127. // keypad /
  128. Keyboard_press('\334');
  129. break;
  130. case 2:
  131. // Case: row 4, col 2
  132. // keypad *
  133. Keyboard_press('\335');
  134. break;
  135. case 3:
  136. // Case: row 4, col 3
  137. if (funcMode){
  138. Keyboard_press(KEY_BACKSPACE);
  139. }else{
  140. //keypad -
  141. Keyboard_press('\336');
  142. }
  143. break;
  144. }
  145. break;
  146. }
  147. return;
  148. } else if (isKeyUp) {
  149. /*
  150. *
  151. * KEY UP EVENTS
  152. *
  153. * Toggle when the key is released
  154. *
  155. */
  156. switch (row) {
  157. case 0:
  158. switch (col) {
  159. case 0:
  160. // Case: row 0, col 0
  161. Keyboard_release('\352');
  162. break;
  163. case 1:
  164. // Case: row 0, col 1
  165. //Fn Key
  166. funcMode = false;
  167. break;
  168. case 2:
  169. // Case: row 0, col 2
  170. // Keypad .
  171. Keyboard_release('\353');
  172. break;
  173. case 3:
  174. // Case: row 0, col 3
  175. //Keypad Enter
  176. Keyboard_release('\340');
  177. break;
  178. }
  179. break;
  180. case 1:
  181. switch (col) {
  182. case 0:
  183. // Case: row 1, col 0
  184. Keyboard_release('\341'); //1
  185. break;
  186. case 1:
  187. // Case: row 1, col 1
  188. Keyboard_release('\342'); //2
  189. break;
  190. case 2:
  191. // Case: row 1, col 2
  192. Keyboard_release('\343'); //3
  193. break;
  194. case 3:
  195. // Case: row 1, col 3
  196. //keypad +
  197. Keyboard_release('\337');
  198. break;
  199. }
  200. break;
  201. case 2:
  202. // Cases for row 2 (col 0, col 1, col 2, col 3)
  203. switch (col) {
  204. case 0:
  205. // Case: row 2, col 0
  206. Keyboard_release('\344'); //4
  207. break;
  208. case 1:
  209. // Case: row 2, col 1
  210. Keyboard_release('\345'); //5
  211. break;
  212. case 2:
  213. // Case: row 2, col 2
  214. Keyboard_release('\346'); //6
  215. break;
  216. case 3:
  217. // Case: row 2, col 3
  218. // Handled in key-down events
  219. break;
  220. }
  221. break;
  222. case 3:
  223. // Cases for row 3 (col 0, col 1, col 2, col 3)
  224. switch (col) {
  225. case 0:
  226. // Case: row 3, col 0
  227. Keyboard_release('\347'); //7
  228. break;
  229. case 1:
  230. // Case: row 3, col 1
  231. Keyboard_release('\350'); //8
  232. break;
  233. case 2:
  234. // Case: row 3, col 2
  235. Keyboard_release('\351'); //9
  236. break;
  237. case 3:
  238. // Case: row 3, col 3
  239. // Handled in key-down events
  240. break;
  241. }
  242. break;
  243. case 4:
  244. // Cases for row 4 (col 0, col 1, col 2, col 3)
  245. switch (col) {
  246. case 0:
  247. // Case: row 4, col 0
  248. //NUM LOCK
  249. Keyboard_release('\333');
  250. break;
  251. case 1:
  252. // Case: row 4, col 1
  253. // keypad /
  254. Keyboard_release('\334');
  255. break;
  256. case 2:
  257. // Case: row 4, col 2
  258. // keypad *
  259. Keyboard_release('\335');
  260. break;
  261. case 3:
  262. // Case: row 4, col 3
  263. if (funcMode){
  264. Keyboard_release(KEY_BACKSPACE);
  265. }else{
  266. //keypad -
  267. Keyboard_release('\336');
  268. }
  269. break;
  270. }
  271. break;
  272. }
  273. return;
  274. }
  275. }