keys.cpp 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  1. ////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright 2016 RWS Inc, All Rights Reserved
  4. //
  5. // This program is free software; you can redistribute it and/or modify
  6. // it under the terms of version 2 of the GNU General Public License as published by
  7. // the Free Software Foundation
  8. //
  9. // This program is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU General Public License along
  15. // with this program; if not, write to the Free Software Foundation, Inc.,
  16. // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. //
  18. // Keys.cpp
  19. // Project: Nostril (aka Postal)
  20. //
  21. // History:
  22. // 03/31/97 JMI Started.
  23. //
  24. // 07/06/97 JMI Changed pu8ScanKey parm in KeyDescriptionToValue
  25. // call from a U8 to a short.
  26. // Also, changed g_apszButtonDescriptions to
  27. // g_apszMouseButtonDescriptions.
  28. //
  29. // 08/10/97 JMI Changed description of 0 to "None" (was "NULL").
  30. //
  31. // 08/24/97 JMI Changed descriptions of Numpad <whatever>s to Numpad
  32. // <whatever symbol>s.
  33. // Also, changed 'UNUSED 59' to 'Semicolon' and 'UNUSED 61'
  34. // to 'Equal'.
  35. //
  36. // 08/27/97 JMI Reduced mouse strings to minimum verbosity.
  37. //
  38. // 10/10/97 JMI Added g_apszJoyButtonDescriptions and
  39. // JoyButtonDescriptionToMask().
  40. //
  41. ////////////////////////////////////////////////////////////////////////////////
  42. //
  43. // Key stuff. I'm not sure if this will ever amount to more than just the
  44. // descriptions.
  45. //
  46. ////////////////////////////////////////////////////////////////////////////////
  47. ////////////////////////////////////////////////////////////////////////////////
  48. // RSPiX Includes.
  49. ////////////////////////////////////////////////////////////////////////////////
  50. #include "RSPiX.h"
  51. ////////////////////////////////////////////////////////////////////////////////
  52. // C Includes.
  53. ////////////////////////////////////////////////////////////////////////////////
  54. #include <string.h>
  55. ////////////////////////////////////////////////////////////////////////////////
  56. // Postal Includes.
  57. ////////////////////////////////////////////////////////////////////////////////
  58. #include "keys.h"
  59. ////////////////////////////////////////////////////////////////////////////////
  60. // Macros.
  61. ////////////////////////////////////////////////////////////////////////////////
  62. // Determines the number of elements in the passed array at compile time.
  63. #define NUM_ELEMENTS(a) (sizeof(a) / sizeof(a[0]) )
  64. ////////////////////////////////////////////////////////////////////////////////
  65. // Data.
  66. ////////////////////////////////////////////////////////////////////////////////
  67. // Array of key descriptors.
  68. extern char* g_apszKeyDescriptions[128] =
  69. {
  70. "None",
  71. "End",
  72. "Home",
  73. "Left",
  74. "Up",
  75. "Right",
  76. "Down",
  77. "UNUSED 7",
  78. "Backspace",
  79. "Tab",
  80. "Insert",
  81. "Delete",
  82. "UNUSED 12",
  83. "Enter",
  84. "Left Shift",
  85. "Shift",
  86. "Right Shift",
  87. "Left Control",
  88. "Control",
  89. "Right Control",
  90. "Left Alt",
  91. "Alt",
  92. "Right Alt",
  93. "UNUSED 23",
  94. "UNUSED 24",
  95. "Page Up",
  96. "Page Down",
  97. "Escape",
  98. "Pause",
  99. "Capital",
  100. "Numlock",
  101. "Scroll",
  102. "Space",
  103. "Print Screen",
  104. "UNUSED 34",
  105. "UNUSED 35",
  106. "UNUSED 36",
  107. "UNUSED 37",
  108. "UNUSED 38",
  109. "Right Quote",
  110. "UNUSED 40",
  111. "UNUSED 41",
  112. "UNUSED 42",
  113. "UNUSED 43",
  114. "Comma",
  115. "Minus",
  116. "Period",
  117. "Slash",
  118. "0",
  119. "1",
  120. "2",
  121. "3",
  122. "4",
  123. "5",
  124. "6",
  125. "7",
  126. "8",
  127. "9",
  128. "UNUSED 58",
  129. "Semicolon",
  130. "UNUSED 60",
  131. "Equals",
  132. "UNUSED 62",
  133. "UNUSED 63",
  134. "UNUSED 64",
  135. "A",
  136. "B",
  137. "C",
  138. "D",
  139. "E",
  140. "F",
  141. "G",
  142. "H",
  143. "I",
  144. "J",
  145. "K",
  146. "L",
  147. "M",
  148. "N",
  149. "O",
  150. "P",
  151. "Q",
  152. "R",
  153. "S",
  154. "T",
  155. "U",
  156. "V",
  157. "W",
  158. "X",
  159. "Y",
  160. "Z",
  161. "Left Bracket",
  162. "Back Slash",
  163. "Right Bracket",
  164. "UNUSED 94",
  165. "UNUSED 95",
  166. "Left Quote",
  167. "Numpad 0",
  168. "Numpad 1",
  169. "Numpad 2",
  170. "Numpad 3",
  171. "Numpad 4",
  172. "Numpad 5",
  173. "Numpad 6",
  174. "Numpad 7",
  175. "Numpad 8",
  176. "Numpad 9",
  177. "Numpad *",
  178. "Numpad +",
  179. "Numpad -",
  180. "Numpad .",
  181. "Numpad /",
  182. "UNUSED 112",
  183. "F1",
  184. "F2",
  185. "F3",
  186. "F4",
  187. "F5",
  188. "F6",
  189. "F7",
  190. "F8",
  191. "F9",
  192. "F10",
  193. "F11",
  194. "F12",
  195. "Left System",
  196. "System",
  197. "Right System"
  198. };
  199. // Array of mouse button descriptors.
  200. extern char* g_apszMouseButtonDescriptions[8] =
  201. {
  202. "None",
  203. "Left",
  204. "Right",
  205. "Middle",
  206. "Button 4",
  207. "Button 5",
  208. "Wheel Up",
  209. "Wheel Down",
  210. };
  211. // Array of joy button descriptors.
  212. extern char* g_apszJoyButtonDescriptions[18] =
  213. {
  214. "None",
  215. "A",
  216. "B",
  217. "X",
  218. "Y",
  219. "Back",
  220. "Guide",
  221. "Start",
  222. "LS",
  223. "RS",
  224. "LB",
  225. "RB",
  226. "Up",
  227. "Down",
  228. "Left",
  229. "Right",
  230. "LT",
  231. "RT"
  232. };
  233. /*
  234. extern char* g_apszJoyButtonDescriptions[16] =
  235. {
  236. "None", // 0000
  237. "A", // 0001
  238. "B", // 0010
  239. "A,B", // 0011
  240. "C", // 0100
  241. "A,C", // 0101
  242. "B,C", // 0110
  243. "A,B,C", // 0111
  244. "D", // 1000
  245. "A,D", // 1001
  246. "B,D", // 1010
  247. "A,B,D", // 1011
  248. "C,D", // 1100
  249. "A,C,D", // 1101
  250. "B,C,D", // 1110
  251. "A,B,C,D", // 1111
  252. };
  253. */
  254. ////////////////////////////////////////////////////////////////////////////////
  255. // Functions.
  256. ////////////////////////////////////////////////////////////////////////////////
  257. ////////////////////////////////////////////////////////////////////////////////
  258. // Given a string, returns the appropriate key code.
  259. ////////////////////////////////////////////////////////////////////////////////
  260. extern short KeyDescriptionToValue( // Returns 0 on success. Returns non-zero, if
  261. // key not found.
  262. char* pszKeyDescriptor, // In: Description of key.
  263. U32* psScanKey) // Out: Key value.
  264. {
  265. short sRes = 1; // Assume failure.
  266. U8 u8KeyIndex;
  267. for (u8KeyIndex = 0; u8KeyIndex < NUM_ELEMENTS(g_apszKeyDescriptions); u8KeyIndex++)
  268. {
  269. if (rspStricmp(pszKeyDescriptor, g_apszKeyDescriptions[u8KeyIndex]) == 0)
  270. {
  271. // Found it!
  272. *psScanKey = u8KeyIndex;
  273. sRes = 0;
  274. break;
  275. }
  276. }
  277. return sRes;
  278. }
  279. ////////////////////////////////////////////////////////////////////////////////
  280. // Given a string, returns the appropriate button mask.
  281. ////////////////////////////////////////////////////////////////////////////////
  282. extern short MouseButtonDescriptionToMask( // Returns 0 on success. Returns
  283. // non-zero, if description not
  284. // found.
  285. char* pszButtonDescriptor, // In: Description of button.
  286. U32* psButtonMask) // Out: Button mask.
  287. {
  288. short sRes = 1; // Assume failure.
  289. short sButtonIndex;
  290. for (sButtonIndex = 0; sButtonIndex < NUM_ELEMENTS(g_apszMouseButtonDescriptions); sButtonIndex++)
  291. {
  292. if (rspStricmp(pszButtonDescriptor, g_apszMouseButtonDescriptions[sButtonIndex]) == 0)
  293. {
  294. // Found it!
  295. *psButtonMask = MouseIndexToBitfield(sButtonIndex);
  296. sRes = 0;
  297. break;
  298. }
  299. }
  300. return sRes;
  301. }
  302. ////////////////////////////////////////////////////////////////////////////////
  303. // Given a string, returns the appropriate button mask.
  304. ////////////////////////////////////////////////////////////////////////////////
  305. extern short JoyButtonDescriptionToMask( // Returns 0 on success. Returns
  306. // non-zero, if description not found.
  307. char* pszButtonDescriptor, // In: Description of button.
  308. U32* psButtonMask) // Out: Button mask.
  309. {
  310. short sRes = 1; // Assume failure.
  311. short sButtonIndex;
  312. for (sButtonIndex = 0; sButtonIndex < NUM_ELEMENTS(g_apszJoyButtonDescriptions); sButtonIndex++)
  313. {
  314. if (rspStricmp(pszButtonDescriptor, g_apszJoyButtonDescriptions[sButtonIndex]) == 0)
  315. {
  316. // Found it!
  317. *psButtonMask = JoyIndexToBitfield(sButtonIndex);
  318. sRes = 0;
  319. break;
  320. }
  321. }
  322. return sRes;
  323. }
  324. ////////////////////////////////////////////////////////////////////////////////
  325. // EOF
  326. ////////////////////////////////////////////////////////////////////////////////