actions.ino 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  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 Enter
  59. Keyboard_press('\340');
  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. break;
  81. }
  82. break;
  83. case 3:
  84. // Cases for row 3 (col 0, col 1, col 2, col 3)
  85. switch (col) {
  86. case 0:
  87. // Case: row 3, col 0
  88. Keyboard_press('\347'); //7
  89. break;
  90. case 1:
  91. // Case: row 3, col 1
  92. Keyboard_press('\350'); //8
  93. break;
  94. case 2:
  95. // Case: row 3, col 2
  96. Keyboard_press('\351'); //9
  97. break;
  98. case 3:
  99. // Case: row 3, col 3
  100. //keypad +
  101. Keyboard_press('\337');
  102. break;
  103. }
  104. break;
  105. case 4:
  106. // Cases for row 4 (col 0, col 1, col 2, col 3)
  107. switch (col) {
  108. case 0:
  109. // Case: row 4, col 0
  110. //NUM LOCK
  111. Keyboard_press('\333');
  112. break;
  113. case 1:
  114. // Case: row 4, col 1
  115. // keypad /
  116. Keyboard_press('\334');
  117. break;
  118. case 2:
  119. // Case: row 4, col 2
  120. // keypad *
  121. Keyboard_press('\335');
  122. break;
  123. case 3:
  124. // Case: row 4, col 3
  125. if (funcMode){
  126. Keyboard_press(KEY_BACKSPACE);
  127. }else{
  128. //keypad -
  129. Keyboard_press('\336');
  130. }
  131. break;
  132. }
  133. break;
  134. }
  135. return;
  136. } else if (isKeyUp) {
  137. /*
  138. *
  139. * KEY UP EVENTS
  140. *
  141. * Toggle when the key is released
  142. *
  143. */
  144. switch (row) {
  145. case 0:
  146. switch (col) {
  147. case 0:
  148. // Case: row 0, col 0
  149. Keyboard_release('\352');
  150. break;
  151. case 1:
  152. // Case: row 0, col 1
  153. //Fn Key
  154. funcMode = false;
  155. break;
  156. case 2:
  157. // Case: row 0, col 2
  158. // Keypad .
  159. Keyboard_release('\353');
  160. break;
  161. case 3:
  162. // Case: row 0, col 3
  163. //Keypad Enter
  164. Keyboard_release('\340');
  165. break;
  166. }
  167. break;
  168. case 1:
  169. switch (col) {
  170. case 0:
  171. // Case: row 1, col 0
  172. Keyboard_release('\341'); //1
  173. break;
  174. case 1:
  175. // Case: row 1, col 1
  176. Keyboard_release('\342'); //2
  177. break;
  178. case 2:
  179. // Case: row 1, col 2
  180. Keyboard_release('\343'); //3
  181. break;
  182. case 3:
  183. // Case: row 1, col 3
  184. //Keypad Enter
  185. Keyboard_release('\340');
  186. break;
  187. }
  188. break;
  189. case 2:
  190. // Cases for row 2 (col 0, col 1, col 2, col 3)
  191. switch (col) {
  192. case 0:
  193. // Case: row 2, col 0
  194. Keyboard_release('\344'); //4
  195. break;
  196. case 1:
  197. // Case: row 2, col 1
  198. Keyboard_release('\345'); //5
  199. break;
  200. case 2:
  201. // Case: row 2, col 2
  202. Keyboard_release('\346'); //6
  203. break;
  204. case 3:
  205. // Case: row 2, col 3
  206. // Handled in key-down events
  207. break;
  208. }
  209. break;
  210. case 3:
  211. // Cases for row 3 (col 0, col 1, col 2, col 3)
  212. switch (col) {
  213. case 0:
  214. // Case: row 3, col 0
  215. Keyboard_release('\347'); //7
  216. break;
  217. case 1:
  218. // Case: row 3, col 1
  219. Keyboard_release('\350'); //8
  220. break;
  221. case 2:
  222. // Case: row 3, col 2
  223. Keyboard_release('\351'); //9
  224. break;
  225. case 3:
  226. // Case: row 3, col 3
  227. //keypad +
  228. Keyboard_release('\337');
  229. break;
  230. }
  231. break;
  232. case 4:
  233. // Cases for row 4 (col 0, col 1, col 2, col 3)
  234. switch (col) {
  235. case 0:
  236. // Case: row 4, col 0
  237. //NUM LOCK
  238. Keyboard_release('\333');
  239. break;
  240. case 1:
  241. // Case: row 4, col 1
  242. // keypad /
  243. Keyboard_release('\334');
  244. break;
  245. case 2:
  246. // Case: row 4, col 2
  247. // keypad *
  248. Keyboard_release('\335');
  249. break;
  250. case 3:
  251. // Case: row 4, col 3
  252. if (funcMode){
  253. Keyboard_release(KEY_BACKSPACE);
  254. }else{
  255. //keypad -
  256. Keyboard_release('\336');
  257. }
  258. break;
  259. }
  260. break;
  261. }
  262. return;
  263. }
  264. }