API Docs for: 1.0.0-beta.2
Show:

File: ../src/layouts/tangiblekeyboard.layout.ipac4.js

  1. /* global define, module, TangibleKeyboard */
  2.  
  3. /**
  4. * #### Overview ####
  5. *
  6. * The I-PAC 4 is a 56-input keyboard emulator manufactured by
  7. * <a href="http://www.ultimarc.com/">Ultimarc</a>. It is mostly used in arcade game
  8. * simulators but is also a popular way to connect switches in physical computing
  9. * projects. This layout will enable you to specify bindings using the labels printed on
  10. * the I-PAC 4 board (`1RGHT`, `2B`, `1SW6`, etc.). This will save you from having to
  11. * look up which keycodes are triggered by which inputs.
  12. *
  13. * #### Usage ####
  14. *
  15. * Using it is quite simple. Simply link to the file and call the `setLayout()` method
  16. * with the `ipac4` identifier:
  17. *
  18. * <script src="tangiblekeyboard.js"></script>
  19. * <script src="layouts/tangiblekeyboard.layout.ipac4.js"></script>
  20. *
  21. * <script>
  22. * TangibleKeyboard.setLayout('ipac4');
  23. *
  24. * TangibleKeyboard.on(
  25. * '1RGHT',
  26. * {
  27. * onKeyDown: function(e, keys, combo) { console.log(e); }
  28. * }
  29. * );
  30. * </script>
  31. *
  32. * That's it.
  33. *
  34. * If you are using AMD or CommonJS, there's an extra step. You will need to
  35. * explicitely register and assign the layout. Here's an example with AMD:
  36. *
  37. * define(function (require) {
  38. *
  39. * var tk = require('tangiblekeyboard');
  40. * var layout = require('layouts/tangiblekeyboard.layout.ipac4');
  41. * tk.registerAndSetLayout("ipac4", layout);
  42. *
  43. * tk.on(
  44. * '1RGHT',
  45. * {
  46. * onKeyDown: function(e, keys, combo) { console.log(e); }
  47. * }
  48. * );
  49. *
  50. * });
  51. *
  52. * #### Warning ####
  53. *
  54. * The I-PAC 4 uses the <a href="http://en.wikipedia.org/wiki/MAME">MAME</a> key mappings
  55. * by default. This means that the `1STRT` input actually behaves like a shift key and
  56. * modifies the key assignment of other inputs when activated. It also means that this
  57. * input will trigger both down and up callbacks at once when released. If you are not
  58. * building a MAME-type arcade simulator, I would urge you not to use this input.
  59. *
  60. * Also note that some inputs are not mapped in the default MAME configuration. For that
  61. * reason, the following inputs are not assigned in this layout:
  62. *
  63. * * `3SW5`
  64. * * `3SW6`
  65. * * `3SW7`
  66. * * `3SW8`
  67. * * `4SW5`
  68. * * `4SW6`
  69. * * `4SW7`
  70. * * `4SW8`
  71. *
  72. * Finally, please note that a few default MAME mappings overlap. This means that the
  73. * following pairs share the same keycode. They are, effectively, interchangeable and
  74. * synonymous:
  75. *
  76. * * `1B` and `3SW3`
  77. * * `2SW7` and 3LEFT`
  78. * * `2SW6` and 3DOWN`
  79. * * `2SW8` and 3RGHT`
  80. * * `1SW8` and 4LEFT`
  81. * * "1SW4", "3SW2"
  82. *
  83. * @module layouts
  84. * @class TangibleKeyboard.layouts.ipac4
  85. */
  86.  
  87. (function(scope) {
  88.  
  89. 'use strict';
  90.  
  91. var layout = {
  92.  
  93. /**
  94. * An enumeration object containing keycode-to-identifier mappings. For example,
  95. * `map["9"]` contains the array `["2A"]`. This means that listening to the "2A"
  96. * key selector will actually listen for events triggered from pressing a key with
  97. * a keycode of 9.
  98. *
  99. * * 9: 2A -> tab
  100. * * 13: 1B -> enter
  101. * * 16: 1SW4 -> left shift
  102. * * 17: 1SW1 -> left control
  103. * * 18: 1SW2 -> left alt
  104. * * 27: 2B -> escape
  105. * * 32: 1SW3 -> space
  106. * * 37: 1LEFT -> left arrow
  107. * * 38: 1UP -> up arrow
  108. * * 39: 1RGHT -> right arrow
  109. * * 40: 1DOWN -> down arrow
  110. * * 49: 1STRT -> 1
  111. * * 50: 2STRT -> 2
  112. * * 53: 1COIN -> 5
  113. * * 54: 2COIN -> 6
  114. * * 65: 2SW1 -> a
  115. * * 67: 1SW7 -> c
  116. * * 68: 2LEFT -> d
  117. * * 70: 2DOWN -> f
  118. * * 71: 2RGHT -> g
  119. * * 73: 2SW5 -> i
  120. * * 74: 2SW7 -> j
  121. * * 75: 2SW6 -> k
  122. * * 76: 2SW8 -> l
  123. * * 80: 1A -> p
  124. * * 81: 2SW3 -> q
  125. * * 82: 2UP -> r
  126. * * 83: 2SW2 -> s
  127. * * 86: 1SW8 -> v
  128. * * 87: 2SW4 -> w
  129. * * 88: 1SW6 -> x
  130. * * 90: 1SW5 -> z
  131. * * 192: ` -> grave accent
  132. *
  133. * @property map
  134. * @type Object
  135. *
  136. */
  137.  
  138. "map": {
  139. "9": ["2A"], // tab
  140. "13": ["1B", "3SW3"], // enter
  141. "16": ["1SW4", "3SW2"], // left shift, right shift
  142. "17": ["1SW1", "3SW1"], // left control, right control
  143. "18": ["1SW2"], // left alt
  144. "27": ["2B"], // escape
  145. "32": ["1SW3"], // space
  146. "37": ["1LEFT"], // left arrow
  147. "38": ["1UP"], // up arrow
  148. "39": ["1RGHT"], // right arrow
  149. "40": ["1DOWN"], // down arrow
  150. "49": ["1STRT"], // 1
  151. "50": ["2STRT"], // 2
  152. "53": ["1COIN"], // 5
  153. "54": ["2COIN"], // 6
  154.  
  155. "65": ["2SW1"], // a
  156. "67": ["1SW7"], // c
  157. "68": ["2LEFT"], // d
  158. "70": ["2DOWN"], // f
  159. "71": ["2RGHT"], // g
  160. "73": ["2SW5"], // i
  161. "74": ["2SW7", "3LEFT"], // j
  162. "75": ["2SW6", "3DOWN"], // k
  163. "76": ["2SW8", "3RGHT"], // l
  164. "80": ["1A"], // p
  165. "81": ["2SW3"], // q
  166. "82": ["2UP"], // r
  167. "83": ["2SW2"], // s
  168. "86": ["1SW8", "4LEFT"], // v
  169. "87": ["2SW4"], // w
  170. "88": ["1SW6"], // x
  171. "90": ["1SW5"], // z
  172.  
  173. "55": ["3COIN"], // 7
  174. "56": ["4COIN"], // 8
  175.  
  176. "51": ["3STRT"], // 3
  177. "52": ["4STRT"], // 4
  178.  
  179. "79": ["3SW4"], // o
  180. "85": ["4RGHT"], // u
  181. "89": ["4UP"], // y
  182. "78": ["4DOWN"], // n
  183.  
  184. "66": ["4SW1"], // b
  185. "69": ["4SW2"], // e
  186. "72": ["4SW3"], // h
  187. "77": ["4SW4"], // m
  188.  
  189. "192": ["`"]
  190. },
  191.  
  192. /**
  193. * An array of all macros defined by this layout. Please note that the IpacVE
  194. * only sends the resulting key and not all keys in the macro sequence. This is
  195. * different from how most regular keyboards work.
  196. *
  197. * * 1STRT + 2STRT : 2B
  198. * * 1STRT + 1RGHT : 2A
  199. * * 1STRT + 1LEFT : 1B
  200. * * 1STRT + 1UP : ` or grave
  201. * * 1STRT + 1DOWN : 1A
  202. * * 1STRT + 1SW1 : 1COIN
  203. *
  204. * @property macros
  205. * @type Array
  206. */
  207. "macros": [
  208. // Those are hardcore macros. The IpacVE will only send the resulting key (not
  209. // 1STRT then 2STRT1, for example).
  210. ['1STRT + 2STRT', ["2B"]],
  211. ['1STRT + 1RGHT', ["2A"]],
  212. ['1STRT + 1LEFT', ["1B"]],
  213. ['1STRT + 1UP', ["`", "grave"]],
  214. ['1STRT + 1DOWN', ["1A"]],
  215. ['1STRT + 1SW1', ["1COIN"]]
  216. ]
  217. };
  218.  
  219. // AMD/RequireJS
  220. if (typeof define === 'function' && define.amd) {
  221. define([], function () {
  222. return layout;
  223. });
  224. }
  225.  
  226. // CommonJS
  227. else if (typeof module !== 'undefined') {
  228. module.exports = layout;
  229. }
  230.  
  231. // Global
  232. else if (scope.TangibleKeyboard) {
  233. scope.TangibleKeyboard.registerLayout('ipacve', layout);
  234. }
  235.  
  236. }(window));