Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1339 lines
38 KiB

  1. //===== Copyright 1996-2005, Valve Corporation, All rights reserved. ======//
  2. //
  3. // Purpose:
  4. //
  5. //===========================================================================//
  6. #include "platform.h"
  7. #if !defined( _GAMECONSOLE ) && !defined( PLATFORM_POSIX )
  8. #include <wtypes.h>
  9. #include <winuser.h>
  10. #include "xbox/xboxstubs.h"
  11. #elif defined( _X360 )
  12. #include "xbox/xbox_win32stubs.h"
  13. #undef unlink
  14. #elif defined( _PS3 )
  15. #include "ps3/ps3_core.h"
  16. #include <cell/keyboard.h>
  17. #endif // WIN32
  18. #if defined( _OSX )
  19. #include "posix_stubs.h"
  20. #endif
  21. #include "key_translation.h"
  22. #include "tier1/convar.h"
  23. #include "tier1/strtools.h"
  24. #include "tier0/dbg.h"
  25. // memdbgon must be the last include file in a .cpp file!!!
  26. #include "tier0/memdbgon.h"
  27. static ButtonCode_t s_pVirtualKeyToButtonCode[256];
  28. static ButtonCode_t s_pSKeytoButtonCode[SK_MAX_KEYS];
  29. #if defined( PLATFORM_WINDOWS ) || defined( _GAMECONSOLE ) || defined( _OSX )
  30. static ButtonCode_t s_pXKeyTrans[XK_MAX_KEYS];
  31. #endif
  32. static int s_pButtonCodeToVirtual[BUTTON_CODE_LAST];
  33. #if defined ( _GAMECONSOLE )
  34. #define JOYSTICK_NAMES_BUTTONS( x ) \
  35. "A_BUTTON",\
  36. "B_BUTTON",\
  37. "X_BUTTON",\
  38. "Y_BUTTON",\
  39. "L_SHOULDER",\
  40. "R_SHOULDER",\
  41. "BACK",\
  42. "START",\
  43. "STICK1",\
  44. "STICK2",\
  45. "JOY11",\
  46. "FIREMODE_1",\
  47. "FIREMODE_2",\
  48. "FIREMODE_3",\
  49. "RELOAD",\
  50. "TRIGGER",\
  51. "PUMP_ACTION",\
  52. "ROLL_RIGHT",\
  53. "ROLL_LEFT",\
  54. "JOY20",\
  55. "JOY21",\
  56. "JOY22",\
  57. "JOY23",\
  58. "JOY24",\
  59. "JOY25",\
  60. "JOY26",\
  61. "JOY27",\
  62. "JOY28",\
  63. "JOY29",\
  64. "JOY30",\
  65. "JOY31",\
  66. "JOY32"
  67. #define JOYSTICK_NAMES_POV( x ) \
  68. "UP",\
  69. "RIGHT",\
  70. "DOWN",\
  71. "LEFT"
  72. #define JOYSTICK_NAMES_AXIS( x ) \
  73. "S1_RIGHT",\
  74. "S1_LEFT",\
  75. "S1_DOWN",\
  76. "S1_UP",\
  77. "L_TRIGGER",\
  78. "R_TRIGGER",\
  79. "S2_RIGHT",\
  80. "S2_LEFT",\
  81. "S2_DOWN",\
  82. "S2_UP",\
  83. "V AXIS POS",\
  84. "V AXIS NEG"
  85. #else
  86. #define JOYSTICK_NAMES_BUTTONS( x ) \
  87. "JOY1", \
  88. "JOY2", \
  89. "JOY3", \
  90. "JOY4", \
  91. "JOY5", \
  92. "JOY6", \
  93. "JOY7", \
  94. "JOY8", \
  95. "JOY9", \
  96. "JOY10", \
  97. "JOY11", \
  98. "JOY12", \
  99. "JOY13", \
  100. "JOY14", \
  101. "JOY15", \
  102. "JOY16", \
  103. "JOY17", \
  104. "JOY18", \
  105. "JOY19", \
  106. "JOY20", \
  107. "JOY21", \
  108. "JOY22", \
  109. "JOY23", \
  110. "JOY24", \
  111. "JOY25", \
  112. "JOY26", \
  113. "JOY27", \
  114. "JOY28", \
  115. "JOY29", \
  116. "JOY30", \
  117. "JOY31", \
  118. "JOY32"
  119. #define JOYSTICK_NAMES_POV( x ) \
  120. "POV_UP",\
  121. "POV_RIGHT",\
  122. "POV_DOWN",\
  123. "POV_LEFT"
  124. #define JOYSTICK_NAMES_AXIS( x ) \
  125. "X AXIS POS",\
  126. "X AXIS NEG",\
  127. "Y AXIS POS",\
  128. "Y AXIS NEG",\
  129. "Z AXIS POS",\
  130. "Z AXIS NEG",\
  131. "R AXIS POS",\
  132. "R AXIS NEG",\
  133. "U AXIS POS",\
  134. "U AXIS NEG",\
  135. "V AXIS POS",\
  136. "V AXIS NEG"
  137. #endif
  138. #define SCONTROLLERBUTTONS_BUTTONS( x ) \
  139. "SC_A",\
  140. "SC_B",\
  141. "SC_X",\
  142. "SC_Y",\
  143. "SC_DPAD_UP",\
  144. "SC_DPAD_RIGHT",\
  145. "SC_DPAD_DOWN",\
  146. "SC_DPAD_LEFT",\
  147. "SC_LEFT_BUMPER",\
  148. "SC_RIGHT_BUMPER",\
  149. "SC_LEFT_TRIGGER",\
  150. "SC_RIGHT_TRIGGER",\
  151. "SC_LEFT_GRIP",\
  152. "SC_RIGHT_GRIP",\
  153. "SC_LEFT_PAD_TOUCH",\
  154. "SC_RIGHT_PAD_TOUCH",\
  155. "SC_LEFT_PAD_CLICK",\
  156. "SC_RIGHT_PAD_CLICK",\
  157. "SC_LPAD_UP",\
  158. "SC_LPAD_RIGHT",\
  159. "SC_LPAD_DOWN",\
  160. "SC_LPAD_LEFT",\
  161. "SC_RPAD_UP",\
  162. "SC_RPAD_RIGHT",\
  163. "SC_RPAD_DOWN",\
  164. "SC_RPAD_LEFT",\
  165. "SC_SELECT",\
  166. "SC_START",\
  167. "SC_STEAM",\
  168. "SC_NULL"
  169. #define SCONTROLLERBUTTONS_AXIS( x ) \
  170. "SC_LPAD_AXIS_RIGHT",\
  171. "SC_LPAD_AXIS_LEFT",\
  172. "SC_LPAD_AXIS_DOWN",\
  173. "SC_LPAD_AXIS_UP",\
  174. "SC_AXIS_L_TRIGGER",\
  175. "SC_AXIS_R_TRIGGER",\
  176. "SC_RPAD_AXIS_RIGHT",\
  177. "SC_RPAD_AXIS_LEFT",\
  178. "SC_RPAD_AXIS_DOWN",\
  179. "SC_RPAD_AXIS_UP",\
  180. "SC_GYRO_AXIS_PITCH_POSITIVE",\
  181. "SC_GYRO_AXIS_PITCH_NEGATIVE",\
  182. "SC_GYRO_AXIS_ROLL_POSITIVE",\
  183. "SC_GYRO_AXIS_ROLL_NEGATIVE",\
  184. "SC_GYRO_AXIS_YAW_POSITIVE",\
  185. "SC_GYRO_AXIS_YAW_NEGATIVE"
  186. #if defined( _PS3 )
  187. static const char *s_pPS3ButtonCodeName[ ] =
  188. {
  189. "", // KEY_NONE
  190. "KEY_0", // KEY_0,
  191. "KEY_1", // KEY_1,
  192. "KEY_2", // KEY_2,
  193. "KEY_3", // KEY_3,
  194. "KEY_4", // KEY_4,
  195. "KEY_5", // KEY_5,
  196. "KEY_6", // KEY_6,
  197. "KEY_7", // KEY_7,
  198. "KEY_8", // KEY_8,
  199. "KEY_9", // KEY_9,
  200. "KEY_A", // KEY_A,
  201. "KEY_B", // KEY_B,
  202. "KEY_C", // KEY_C,
  203. "KEY_D", // KEY_D,
  204. "KEY_E", // KEY_E,
  205. "KEY_F", // KEY_F,
  206. "KEY_G", // KEY_G,
  207. "KEY_H", // KEY_H,
  208. "KEY_I", // KEY_I,
  209. "KEY_J", // KEY_J,
  210. "KEY_K", // KEY_K,
  211. "KEY_L", // KEY_L,
  212. "KEY_M", // KEY_M,
  213. "KEY_N", // KEY_N,
  214. "KEY_O", // KEY_O,
  215. "KEY_P", // KEY_P,
  216. "KEY_Q", // KEY_Q,
  217. "KEY_R", // KEY_R,
  218. "KEY_S", // KEY_S,
  219. "KEY_T", // KEY_T,
  220. "KEY_U", // KEY_U,
  221. "KEY_V", // KEY_V,
  222. "KEY_W", // KEY_W,
  223. "KEY_X", // KEY_X,
  224. "KEY_Y", // KEY_Y,
  225. "KEY_Z", // KEY_Z,
  226. "KP_INS", // KEY_PAD_0,
  227. "KP_END", // KEY_PAD_1,
  228. "KP_DOWNARROW", // KEY_PAD_2,
  229. "KP_PGDN", // KEY_PAD_3,
  230. "KP_LEFTARROW", // KEY_PAD_4,
  231. "KP_5", // KEY_PAD_5,
  232. "KP_RIGHTARROW",// KEY_PAD_6,
  233. "KP_HOME", // KEY_PAD_7,
  234. "KP_UPARROW", // KEY_PAD_8,
  235. "KP_PGUP", // KEY_PAD_9,
  236. "KP_SLASH", // KEY_PAD_DIVIDE,
  237. "KP_MULTIPLY", // KEY_PAD_MULTIPLY,
  238. "KP_MINUS", // KEY_PAD_MINUS,
  239. "KP_PLUS", // KEY_PAD_PLUS,
  240. "KP_ENTER", // KEY_PAD_ENTER,
  241. "KP_DEL", // KEY_PAD_DECIMAL,
  242. "LBRACKET", // KEY_LBRACKET,
  243. "RBRACKET", // KEY_RBRACKET,
  244. "SEMICOLON", // KEY_SEMICOLON,
  245. "APOSTROPHE", // KEY_APOSTROPHE,
  246. "BACKQUOTE", // KEY_BACKQUOTE,
  247. "COMMA", // KEY_COMMA,
  248. "PERIOD", // KEY_PERIOD,
  249. "SLASH", // KEY_SLASH,
  250. "BACKSLASH", // KEY_BACKSLASH,
  251. "MINUS", // KEY_MINUS,
  252. "EQUAL", // KEY_EQUAL,
  253. "ENTER", // KEY_ENTER,
  254. "SPACE", // KEY_SPACE,
  255. "BACKSPACE", // KEY_BACKSPACE,
  256. "TAB", // KEY_TAB,
  257. "CAPSLOCK", // KEY_CAPSLOCK,
  258. "NUMLOCK", // KEY_NUMLOCK,
  259. "ESCAPE", // KEY_ESCAPE,
  260. "SCROLLLOCK", // KEY_SCROLLLOCK,
  261. "INS", // KEY_INSERT,
  262. "DEL", // KEY_DELETE,
  263. "HOME", // KEY_HOME,
  264. "END", // KEY_END,
  265. "PGUP", // KEY_PAGEUP,
  266. "PGDN", // KEY_PAGEDOWN,
  267. "PAUSE", // KEY_BREAK,
  268. "SHIFT", // KEY_LSHIFT,
  269. "RSHIFT", // KEY_RSHIFT,
  270. "ALT", // KEY_LALT,
  271. "RALT", // KEY_RALT,
  272. "CTRL", // KEY_LCONTROL,
  273. "RCTRL", // KEY_RCONTROL,
  274. "LWIN", // KEY_LWIN,
  275. "RWIN", // KEY_RWIN,
  276. "APP", // KEY_APP,
  277. "UPARROW", // KEY_UP,
  278. "LEFTARROW", // KEY_LEFT,
  279. "DOWNARROW", // KEY_DOWN,
  280. "RIGHTARROW", // KEY_RIGHT,
  281. "F1", // KEY_F1,
  282. "F2", // KEY_F2,
  283. "F3", // KEY_F3,
  284. "F4", // KEY_F4,
  285. "F5", // KEY_F5,
  286. "F6", // KEY_F6,
  287. "F7", // KEY_F7,
  288. "F8", // KEY_F8,
  289. "F9", // KEY_F9,
  290. "F10", // KEY_F10,
  291. "F11", // KEY_F11,
  292. "F12", // KEY_F12,
  293. // FIXME: CAPSLOCK/NUMLOCK/SCROLLLOCK all appear above. What are these for?!
  294. // They only appear in CInputWin32::UpdateToggleButtonState in vgui2
  295. "CAPSLOCKTOGGLE", // KEY_CAPSLOCKTOGGLE,
  296. "NUMLOCKTOGGLE", // KEY_NUMLOCKTOGGLE,
  297. "SCROLLLOCKTOGGLE", // KEY_SCROLLLOCKTOGGLE,
  298. // Mouse
  299. "MOUSE1", // MOUSE_LEFT,
  300. "MOUSE2", // MOUSE_RIGHT,
  301. "MOUSE3", // MOUSE_MIDDLE,
  302. "MOUSE4", // MOUSE_4,
  303. "MOUSE5", // MOUSE_5,
  304. "MWHEELUP", // MOUSE_WHEEL_UP
  305. "MWHEELDOWN", // MOUSE_WHEEL_DOWN
  306. JOYSTICK_NAMES_BUTTONS( 0 ),
  307. JOYSTICK_NAMES_BUTTONS( 1 ),
  308. JOYSTICK_NAMES_BUTTONS( 2 ),
  309. JOYSTICK_NAMES_BUTTONS( 3 ),
  310. JOYSTICK_NAMES_BUTTONS( 4 ),
  311. JOYSTICK_NAMES_BUTTONS( 5 ),
  312. JOYSTICK_NAMES_BUTTONS( 6 ),
  313. JOYSTICK_NAMES_POV( 0 ),
  314. JOYSTICK_NAMES_POV( 1 ),
  315. JOYSTICK_NAMES_POV( 2 ),
  316. JOYSTICK_NAMES_POV( 3 ),
  317. JOYSTICK_NAMES_POV( 4 ),
  318. JOYSTICK_NAMES_POV( 5 ),
  319. JOYSTICK_NAMES_POV( 6 ),
  320. JOYSTICK_NAMES_AXIS( 0 ),
  321. JOYSTICK_NAMES_AXIS( 1 ),
  322. JOYSTICK_NAMES_AXIS( 2 ),
  323. JOYSTICK_NAMES_AXIS( 3 ),
  324. JOYSTICK_NAMES_AXIS( 4 ),
  325. JOYSTICK_NAMES_AXIS( 5 ),
  326. JOYSTICK_NAMES_AXIS( 6 ),
  327. };
  328. #endif
  329. static const char *s_pButtonCodeName[ ] =
  330. {
  331. "", // KEY_NONE
  332. "0", // KEY_0,
  333. "1", // KEY_1,
  334. "2", // KEY_2,
  335. "3", // KEY_3,
  336. "4", // KEY_4,
  337. "5", // KEY_5,
  338. "6", // KEY_6,
  339. "7", // KEY_7,
  340. "8", // KEY_8,
  341. "9", // KEY_9,
  342. "a", // KEY_A,
  343. "b", // KEY_B,
  344. "c", // KEY_C,
  345. "d", // KEY_D,
  346. "e", // KEY_E,
  347. "f", // KEY_F,
  348. "g", // KEY_G,
  349. "h", // KEY_H,
  350. "i", // KEY_I,
  351. "j", // KEY_J,
  352. "k", // KEY_K,
  353. "l", // KEY_L,
  354. "m", // KEY_M,
  355. "n", // KEY_N,
  356. "o", // KEY_O,
  357. "p", // KEY_P,
  358. "q", // KEY_Q,
  359. "r", // KEY_R,
  360. "s", // KEY_S,
  361. "t", // KEY_T,
  362. "u", // KEY_U,
  363. "v", // KEY_V,
  364. "w", // KEY_W,
  365. "x", // KEY_X,
  366. "y", // KEY_Y,
  367. "z", // KEY_Z,
  368. "KP_INS", // KEY_PAD_0,
  369. "KP_END", // KEY_PAD_1,
  370. "KP_DOWNARROW", // KEY_PAD_2,
  371. "KP_PGDN", // KEY_PAD_3,
  372. "KP_LEFTARROW", // KEY_PAD_4,
  373. "KP_5", // KEY_PAD_5,
  374. "KP_RIGHTARROW",// KEY_PAD_6,
  375. "KP_HOME", // KEY_PAD_7,
  376. "KP_UPARROW", // KEY_PAD_8,
  377. "KP_PGUP", // KEY_PAD_9,
  378. "KP_SLASH", // KEY_PAD_DIVIDE,
  379. "KP_MULTIPLY", // KEY_PAD_MULTIPLY,
  380. "KP_MINUS", // KEY_PAD_MINUS,
  381. "KP_PLUS", // KEY_PAD_PLUS,
  382. "KP_ENTER", // KEY_PAD_ENTER,
  383. "KP_DEL", // KEY_PAD_DECIMAL,
  384. "[", // KEY_LBRACKET,
  385. "]", // KEY_RBRACKET,
  386. "SEMICOLON", // KEY_SEMICOLON,
  387. "'", // KEY_APOSTROPHE,
  388. "`", // KEY_BACKQUOTE,
  389. ",", // KEY_COMMA,
  390. ".", // KEY_PERIOD,
  391. "/", // KEY_SLASH,
  392. "\\", // KEY_BACKSLASH,
  393. "-", // KEY_MINUS,
  394. "=", // KEY_EQUAL,
  395. "ENTER", // KEY_ENTER,
  396. "SPACE", // KEY_SPACE,
  397. "BACKSPACE", // KEY_BACKSPACE,
  398. "TAB", // KEY_TAB,
  399. "CAPSLOCK", // KEY_CAPSLOCK,
  400. "NUMLOCK", // KEY_NUMLOCK,
  401. "ESCAPE", // KEY_ESCAPE,
  402. "SCROLLLOCK", // KEY_SCROLLLOCK,
  403. "INS", // KEY_INSERT,
  404. "DEL", // KEY_DELETE,
  405. "HOME", // KEY_HOME,
  406. "END", // KEY_END,
  407. "PGUP", // KEY_PAGEUP,
  408. "PGDN", // KEY_PAGEDOWN,
  409. "PAUSE", // KEY_BREAK,
  410. "SHIFT", // KEY_LSHIFT,
  411. "RSHIFT", // KEY_RSHIFT,
  412. "ALT", // KEY_LALT,
  413. "RALT", // KEY_RALT,
  414. "CTRL", // KEY_LCONTROL,
  415. "RCTRL", // KEY_RCONTROL,
  416. #if defined(OSX)
  417. "COMMAND", // KEY_LWIN
  418. "COMMAND", // KEY_RWIN
  419. #else
  420. "LWIN", // KEY_LWIN,
  421. "RWIN", // KEY_RWIN,
  422. #endif
  423. "APP", // KEY_APP,
  424. "UPARROW", // KEY_UP,
  425. "LEFTARROW", // KEY_LEFT,
  426. "DOWNARROW", // KEY_DOWN,
  427. "RIGHTARROW", // KEY_RIGHT,
  428. "F1", // KEY_F1,
  429. "F2", // KEY_F2,
  430. "F3", // KEY_F3,
  431. "F4", // KEY_F4,
  432. "F5", // KEY_F5,
  433. "F6", // KEY_F6,
  434. "F7", // KEY_F7,
  435. "F8", // KEY_F8,
  436. "F9", // KEY_F9,
  437. "F10", // KEY_F10,
  438. "F11", // KEY_F11,
  439. "F12", // KEY_F12,
  440. // FIXME: CAPSLOCK/NUMLOCK/SCROLLLOCK all appear above. What are these for?!
  441. // They only appear in CInputWin32::UpdateToggleButtonState in vgui2
  442. "CAPSLOCKTOGGLE", // KEY_CAPSLOCKTOGGLE,
  443. "NUMLOCKTOGGLE", // KEY_NUMLOCKTOGGLE,
  444. "SCROLLLOCKTOGGLE", // KEY_SCROLLLOCKTOGGLE,
  445. // Mouse
  446. "MOUSE1", // MOUSE_LEFT,
  447. "MOUSE2", // MOUSE_RIGHT,
  448. "MOUSE3", // MOUSE_MIDDLE,
  449. "MOUSE4", // MOUSE_4,
  450. "MOUSE5", // MOUSE_5,
  451. "MWHEELUP", // MOUSE_WHEEL_UP
  452. "MWHEELDOWN", // MOUSE_WHEEL_DOWN
  453. JOYSTICK_NAMES_BUTTONS( 0 ),
  454. JOYSTICK_NAMES_BUTTONS( 1 ),
  455. JOYSTICK_NAMES_BUTTONS( 2 ),
  456. JOYSTICK_NAMES_BUTTONS( 3 ),
  457. #ifdef _PS3
  458. JOYSTICK_NAMES_BUTTONS( 4 ),
  459. JOYSTICK_NAMES_BUTTONS( 5 ),
  460. JOYSTICK_NAMES_BUTTONS( 6 ),
  461. #endif
  462. JOYSTICK_NAMES_POV( 0 ),
  463. JOYSTICK_NAMES_POV( 1 ),
  464. JOYSTICK_NAMES_POV( 2 ),
  465. JOYSTICK_NAMES_POV( 3 ),
  466. #ifdef _PS3
  467. JOYSTICK_NAMES_POV( 4 ),
  468. JOYSTICK_NAMES_POV( 5 ),
  469. JOYSTICK_NAMES_POV( 6 ),
  470. #endif
  471. JOYSTICK_NAMES_AXIS( 0 ),
  472. JOYSTICK_NAMES_AXIS( 1 ),
  473. JOYSTICK_NAMES_AXIS( 2 ),
  474. JOYSTICK_NAMES_AXIS( 3 ),
  475. #ifdef _PS3
  476. JOYSTICK_NAMES_AXIS( 4 ),
  477. JOYSTICK_NAMES_AXIS( 5 ),
  478. JOYSTICK_NAMES_AXIS( 6 ),
  479. #endif
  480. SCONTROLLERBUTTONS_BUTTONS( 0 ),
  481. SCONTROLLERBUTTONS_BUTTONS( 1 ),
  482. SCONTROLLERBUTTONS_BUTTONS( 2 ),
  483. SCONTROLLERBUTTONS_BUTTONS( 3 ),
  484. SCONTROLLERBUTTONS_BUTTONS( 4 ),
  485. SCONTROLLERBUTTONS_BUTTONS( 5 ),
  486. SCONTROLLERBUTTONS_BUTTONS( 6 ),
  487. SCONTROLLERBUTTONS_BUTTONS( 7 ),
  488. SCONTROLLERBUTTONS_BUTTONS( 8 ),
  489. SCONTROLLERBUTTONS_BUTTONS( 9 ),
  490. SCONTROLLERBUTTONS_BUTTONS( 10 ),
  491. SCONTROLLERBUTTONS_BUTTONS( 11 ),
  492. SCONTROLLERBUTTONS_BUTTONS( 12 ),
  493. SCONTROLLERBUTTONS_BUTTONS( 13 ),
  494. SCONTROLLERBUTTONS_BUTTONS( 14 ),
  495. SCONTROLLERBUTTONS_BUTTONS( 15 ),
  496. SCONTROLLERBUTTONS_AXIS( 0 ),
  497. SCONTROLLERBUTTONS_AXIS( 1 ),
  498. SCONTROLLERBUTTONS_AXIS( 2 ),
  499. SCONTROLLERBUTTONS_AXIS( 3 ),
  500. SCONTROLLERBUTTONS_AXIS( 4 ),
  501. SCONTROLLERBUTTONS_AXIS( 5 ),
  502. SCONTROLLERBUTTONS_AXIS( 6 ),
  503. SCONTROLLERBUTTONS_AXIS( 7 ),
  504. SCONTROLLERBUTTONS_AXIS( 8 ),
  505. SCONTROLLERBUTTONS_AXIS( 9 ),
  506. SCONTROLLERBUTTONS_AXIS( 10 ),
  507. SCONTROLLERBUTTONS_AXIS( 11 ),
  508. SCONTROLLERBUTTONS_AXIS( 12 ),
  509. SCONTROLLERBUTTONS_AXIS( 13 ),
  510. SCONTROLLERBUTTONS_AXIS( 14 ),
  511. SCONTROLLERBUTTONS_AXIS( 15 ),
  512. };
  513. #define JOYSTICK_ANALOG( x ) \
  514. "X AXIS",\
  515. "Y AXIS",\
  516. "Z AXIS",\
  517. "R AXIS",\
  518. "U AXIS",\
  519. "V AXIS"
  520. static const char *s_pAnalogCodeName[ ] =
  521. {
  522. "MOUSE_X", // MOUSE_X = 0,
  523. "MOUSE_Y", // MOUSE_Y,
  524. "MOUSE_XY", // MOUSE_XY, // Invoked when either x or y changes
  525. "MOUSE_WHEEL", // MOUSE_WHEEL,
  526. JOYSTICK_ANALOG( 0 ),
  527. JOYSTICK_ANALOG( 1 ),
  528. JOYSTICK_ANALOG( 2 ),
  529. JOYSTICK_ANALOG( 3 ),
  530. #ifdef _PS3
  531. JOYSTICK_ANALOG( 4 ),
  532. JOYSTICK_ANALOG( 5 ),
  533. JOYSTICK_ANALOG( 6 ),
  534. #endif
  535. };
  536. #if !defined ( _GAMECONSOLE )
  537. #define XCONTROLLERBUTTONS_BUTTONS( x ) \
  538. "A_BUTTON",\
  539. "B_BUTTON",\
  540. "X_BUTTON",\
  541. "Y_BUTTON",\
  542. "L_SHOULDER",\
  543. "R_SHOULDER",\
  544. "BACK",\
  545. "START",\
  546. "STICK1",\
  547. "STICK2",\
  548. "JOY11",\
  549. "JOY12",\
  550. "JOY13",\
  551. "JOY14",\
  552. "JOY15",\
  553. "JOY16",\
  554. "JOY17",\
  555. "JOY18",\
  556. "JOY19",\
  557. "JOY20",\
  558. "JOY21",\
  559. "JOY22",\
  560. "JOY23",\
  561. "JOY24",\
  562. "JOY25",\
  563. "JOY26",\
  564. "JOY27",\
  565. "JOY28",\
  566. "JOY29",\
  567. "JOY30",\
  568. "JOY31",\
  569. "JOY32"
  570. #define XCONTROLLERBUTTONS_POV( x ) \
  571. "UP",\
  572. "RIGHT",\
  573. "DOWN",\
  574. "LEFT"
  575. #define XCONTROLLERBUTTONS_AXIS( x ) \
  576. "S1_RIGHT",\
  577. "S1_LEFT",\
  578. "S1_DOWN",\
  579. "S1_UP",\
  580. "L_TRIGGER",\
  581. "R_TRIGGER",\
  582. "S2_RIGHT",\
  583. "S2_LEFT",\
  584. "S2_DOWN",\
  585. "S2_UP",\
  586. "V AXIS POS",\
  587. "V AXIS NEG"
  588. static const char *s_pXControllerButtonCodeNames[ ] =
  589. {
  590. XCONTROLLERBUTTONS_BUTTONS( 0 ),
  591. XCONTROLLERBUTTONS_BUTTONS( 1 ),
  592. XCONTROLLERBUTTONS_BUTTONS( 2 ),
  593. XCONTROLLERBUTTONS_BUTTONS( 3 ),
  594. #ifdef _PS3
  595. XCONTROLLERBUTTONS_BUTTONS( 4 ),
  596. XCONTROLLERBUTTONS_BUTTONS( 5 ),
  597. XCONTROLLERBUTTONS_BUTTONS( 6 ),
  598. #endif
  599. XCONTROLLERBUTTONS_POV( 0 ),
  600. XCONTROLLERBUTTONS_POV( 1 ),
  601. XCONTROLLERBUTTONS_POV( 2 ),
  602. XCONTROLLERBUTTONS_POV( 3 ),
  603. #ifdef _PS3
  604. XCONTROLLERBUTTONS_POV( 4 ),
  605. XCONTROLLERBUTTONS_POV( 5 ),
  606. XCONTROLLERBUTTONS_POV( 6 ),
  607. #endif
  608. XCONTROLLERBUTTONS_AXIS( 0 ),
  609. XCONTROLLERBUTTONS_AXIS( 1 ),
  610. XCONTROLLERBUTTONS_AXIS( 2 ),
  611. XCONTROLLERBUTTONS_AXIS( 3 ),
  612. #ifdef _PS3
  613. XCONTROLLERBUTTONS_AXIS( 4 ),
  614. XCONTROLLERBUTTONS_AXIS( 5 ),
  615. XCONTROLLERBUTTONS_AXIS( 6 ),
  616. #endif
  617. };
  618. static const char *s_pSControllerButtonCodeNames[ ] =
  619. {
  620. SCONTROLLERBUTTONS_BUTTONS( 0 ),
  621. SCONTROLLERBUTTONS_BUTTONS( 1 ),
  622. SCONTROLLERBUTTONS_BUTTONS( 2 ),
  623. SCONTROLLERBUTTONS_BUTTONS( 3 ),
  624. SCONTROLLERBUTTONS_BUTTONS( 4 ),
  625. SCONTROLLERBUTTONS_BUTTONS( 5 ),
  626. SCONTROLLERBUTTONS_BUTTONS( 6 ),
  627. SCONTROLLERBUTTONS_BUTTONS( 7 ),
  628. SCONTROLLERBUTTONS_AXIS( 0 ),
  629. SCONTROLLERBUTTONS_AXIS( 1 ),
  630. SCONTROLLERBUTTONS_AXIS( 2 ),
  631. SCONTROLLERBUTTONS_AXIS( 3 ),
  632. SCONTROLLERBUTTONS_AXIS( 4 ),
  633. SCONTROLLERBUTTONS_AXIS( 5 ),
  634. SCONTROLLERBUTTONS_AXIS( 6 ),
  635. SCONTROLLERBUTTONS_AXIS( 7 ),
  636. };
  637. #endif
  638. // this maps non-translated keyboard scan codes to engine key codes
  639. // Google for 'Keyboard Scan Code Specification'
  640. static ButtonCode_t s_pScanToButtonCode_QWERTY[128] =
  641. {
  642. // 0 1 2 3 4 5 6 7
  643. // 8 9 A B C D E F
  644. KEY_NONE, KEY_ESCAPE, KEY_1, KEY_2, KEY_3, KEY_4, KEY_5, KEY_6, // 0
  645. KEY_7, KEY_8, KEY_9, KEY_0, KEY_MINUS, KEY_EQUAL, KEY_BACKSPACE, KEY_TAB, // 0
  646. KEY_Q, KEY_W, KEY_E, KEY_R, KEY_T, KEY_Y, KEY_U, KEY_I, // 1
  647. KEY_O, KEY_P, KEY_LBRACKET, KEY_RBRACKET, KEY_ENTER, KEY_LCONTROL, KEY_A, KEY_S, // 1
  648. KEY_D, KEY_F, KEY_G, KEY_H, KEY_J, KEY_K, KEY_L, KEY_SEMICOLON, // 2
  649. KEY_APOSTROPHE, KEY_BACKQUOTE, KEY_LSHIFT, KEY_BACKSLASH, KEY_Z, KEY_X, KEY_C, KEY_V, // 2
  650. KEY_B, KEY_N, KEY_M, KEY_COMMA, KEY_PERIOD, KEY_SLASH, KEY_RSHIFT, KEY_PAD_MULTIPLY,// 3
  651. KEY_LALT, KEY_SPACE, KEY_CAPSLOCK, KEY_F1, KEY_F2, KEY_F3, KEY_F4, KEY_F5, // 3
  652. KEY_F6, KEY_F7, KEY_F8, KEY_F9, KEY_F10, KEY_NUMLOCK, KEY_SCROLLLOCK, KEY_HOME, // 4
  653. KEY_UP, KEY_PAGEUP, KEY_PAD_MINUS, KEY_LEFT, KEY_PAD_5, KEY_RIGHT, KEY_PAD_PLUS, KEY_END, // 4
  654. KEY_DOWN, KEY_PAGEDOWN, KEY_INSERT, KEY_DELETE, KEY_NONE, KEY_NONE, KEY_NONE, KEY_F11, // 5
  655. KEY_F12, KEY_BREAK, KEY_NONE, KEY_NONE, KEY_NONE, KEY_NONE, KEY_NONE, KEY_NONE, // 5
  656. KEY_NONE, KEY_NONE, KEY_NONE, KEY_NONE, KEY_NONE, KEY_NONE, KEY_NONE, KEY_NONE, // 6
  657. KEY_NONE, KEY_NONE, KEY_NONE, KEY_NONE, KEY_NONE, KEY_NONE, KEY_NONE, KEY_NONE, // 6
  658. KEY_NONE, KEY_NONE, KEY_NONE, KEY_NONE, KEY_NONE, KEY_NONE, KEY_NONE, KEY_NONE, // 7
  659. KEY_NONE, KEY_NONE, KEY_NONE, KEY_NONE, KEY_NONE, KEY_NONE, KEY_NONE, KEY_NONE // 7
  660. };
  661. static ButtonCode_t s_pScanToButtonCode[128];
  662. void ButtonCode_InitKeyTranslationTable()
  663. {
  664. #if defined( _PS3 )
  665. COMPILE_TIME_ASSERT( sizeof(s_pPS3ButtonCodeName) / sizeof( const char * ) == BUTTON_CODE_LAST );
  666. #endif
  667. COMPILE_TIME_ASSERT( sizeof(s_pButtonCodeName) / sizeof( const char * ) == BUTTON_CODE_LAST );
  668. COMPILE_TIME_ASSERT( sizeof(s_pAnalogCodeName) / sizeof( const char * ) == ANALOG_CODE_LAST );
  669. // For debugging, spews entire mapping
  670. #if 0
  671. for ( int i = 0; i < BUTTON_CODE_LAST; ++i )
  672. {
  673. Msg( "code %d == %s\n", i, s_pButtonCodeName[ i ] );
  674. }
  675. #endif
  676. // set virtual key translation table
  677. memset( s_pVirtualKeyToButtonCode, KEY_NONE, sizeof(s_pVirtualKeyToButtonCode) );
  678. #if defined ( _PS3 )
  679. s_pVirtualKeyToButtonCode[CELL_KEYC_0] =KEY_0;
  680. s_pVirtualKeyToButtonCode[CELL_KEYC_1] =KEY_1;
  681. s_pVirtualKeyToButtonCode[CELL_KEYC_2] =KEY_2;
  682. s_pVirtualKeyToButtonCode[CELL_KEYC_3] =KEY_3;
  683. s_pVirtualKeyToButtonCode[CELL_KEYC_4] =KEY_4;
  684. s_pVirtualKeyToButtonCode[CELL_KEYC_5] =KEY_5;
  685. s_pVirtualKeyToButtonCode[CELL_KEYC_6] =KEY_6;
  686. s_pVirtualKeyToButtonCode[CELL_KEYC_7] =KEY_7;
  687. s_pVirtualKeyToButtonCode[CELL_KEYC_8] =KEY_8;
  688. s_pVirtualKeyToButtonCode[CELL_KEYC_9] =KEY_9;
  689. s_pVirtualKeyToButtonCode[CELL_KEYC_A] =KEY_A;
  690. s_pVirtualKeyToButtonCode[CELL_KEYC_B] =KEY_B;
  691. s_pVirtualKeyToButtonCode[CELL_KEYC_C] =KEY_C;
  692. s_pVirtualKeyToButtonCode[CELL_KEYC_D] =KEY_D;
  693. s_pVirtualKeyToButtonCode[CELL_KEYC_E] =KEY_E;
  694. s_pVirtualKeyToButtonCode[CELL_KEYC_F] =KEY_F;
  695. s_pVirtualKeyToButtonCode[CELL_KEYC_G] =KEY_G;
  696. s_pVirtualKeyToButtonCode[CELL_KEYC_H] =KEY_H;
  697. s_pVirtualKeyToButtonCode[CELL_KEYC_I] =KEY_I;
  698. s_pVirtualKeyToButtonCode[CELL_KEYC_J] =KEY_J;
  699. s_pVirtualKeyToButtonCode[CELL_KEYC_K] =KEY_K;
  700. s_pVirtualKeyToButtonCode[CELL_KEYC_L] =KEY_L;
  701. s_pVirtualKeyToButtonCode[CELL_KEYC_M] =KEY_M;
  702. s_pVirtualKeyToButtonCode[CELL_KEYC_N] =KEY_N;
  703. s_pVirtualKeyToButtonCode[CELL_KEYC_O] =KEY_O;
  704. s_pVirtualKeyToButtonCode[CELL_KEYC_P] =KEY_P;
  705. s_pVirtualKeyToButtonCode[CELL_KEYC_Q] =KEY_Q;
  706. s_pVirtualKeyToButtonCode[CELL_KEYC_R] =KEY_R;
  707. s_pVirtualKeyToButtonCode[CELL_KEYC_S] =KEY_S;
  708. s_pVirtualKeyToButtonCode[CELL_KEYC_T] =KEY_T;
  709. s_pVirtualKeyToButtonCode[CELL_KEYC_U] =KEY_U;
  710. s_pVirtualKeyToButtonCode[CELL_KEYC_V] =KEY_V;
  711. s_pVirtualKeyToButtonCode[CELL_KEYC_W] =KEY_W;
  712. s_pVirtualKeyToButtonCode[CELL_KEYC_X] =KEY_X;
  713. s_pVirtualKeyToButtonCode[CELL_KEYC_Y] =KEY_Y;
  714. s_pVirtualKeyToButtonCode[CELL_KEYC_Z] =KEY_Z;
  715. #else
  716. s_pVirtualKeyToButtonCode['0'] =KEY_0;
  717. s_pVirtualKeyToButtonCode['1'] =KEY_1;
  718. s_pVirtualKeyToButtonCode['2'] =KEY_2;
  719. s_pVirtualKeyToButtonCode['3'] =KEY_3;
  720. s_pVirtualKeyToButtonCode['4'] =KEY_4;
  721. s_pVirtualKeyToButtonCode['5'] =KEY_5;
  722. s_pVirtualKeyToButtonCode['6'] =KEY_6;
  723. s_pVirtualKeyToButtonCode['7'] =KEY_7;
  724. s_pVirtualKeyToButtonCode['8'] =KEY_8;
  725. s_pVirtualKeyToButtonCode['9'] =KEY_9;
  726. s_pVirtualKeyToButtonCode['A'] =KEY_A;
  727. s_pVirtualKeyToButtonCode['B'] =KEY_B;
  728. s_pVirtualKeyToButtonCode['C'] =KEY_C;
  729. s_pVirtualKeyToButtonCode['D'] =KEY_D;
  730. s_pVirtualKeyToButtonCode['E'] =KEY_E;
  731. s_pVirtualKeyToButtonCode['F'] =KEY_F;
  732. s_pVirtualKeyToButtonCode['G'] =KEY_G;
  733. s_pVirtualKeyToButtonCode['H'] =KEY_H;
  734. s_pVirtualKeyToButtonCode['I'] =KEY_I;
  735. s_pVirtualKeyToButtonCode['J'] =KEY_J;
  736. s_pVirtualKeyToButtonCode['K'] =KEY_K;
  737. s_pVirtualKeyToButtonCode['L'] =KEY_L;
  738. s_pVirtualKeyToButtonCode['M'] =KEY_M;
  739. s_pVirtualKeyToButtonCode['N'] =KEY_N;
  740. s_pVirtualKeyToButtonCode['O'] =KEY_O;
  741. s_pVirtualKeyToButtonCode['P'] =KEY_P;
  742. s_pVirtualKeyToButtonCode['Q'] =KEY_Q;
  743. s_pVirtualKeyToButtonCode['R'] =KEY_R;
  744. s_pVirtualKeyToButtonCode['S'] =KEY_S;
  745. s_pVirtualKeyToButtonCode['T'] =KEY_T;
  746. s_pVirtualKeyToButtonCode['U'] =KEY_U;
  747. s_pVirtualKeyToButtonCode['V'] =KEY_V;
  748. s_pVirtualKeyToButtonCode['W'] =KEY_W;
  749. s_pVirtualKeyToButtonCode['X'] =KEY_X;
  750. s_pVirtualKeyToButtonCode['Y'] =KEY_Y;
  751. s_pVirtualKeyToButtonCode['Z'] =KEY_Z;
  752. #endif
  753. #if defined ( _PS3 )
  754. s_pVirtualKeyToButtonCode[CELL_KEYC_KPAD_0] =KEY_PAD_0;
  755. s_pVirtualKeyToButtonCode[CELL_KEYC_KPAD_1] =KEY_PAD_1;
  756. s_pVirtualKeyToButtonCode[CELL_KEYC_KPAD_2] =KEY_PAD_2;
  757. s_pVirtualKeyToButtonCode[CELL_KEYC_KPAD_3] =KEY_PAD_3;
  758. s_pVirtualKeyToButtonCode[CELL_KEYC_KPAD_4] =KEY_PAD_4;
  759. s_pVirtualKeyToButtonCode[CELL_KEYC_KPAD_5] =KEY_PAD_5;
  760. s_pVirtualKeyToButtonCode[CELL_KEYC_KPAD_6] =KEY_PAD_6;
  761. s_pVirtualKeyToButtonCode[CELL_KEYC_KPAD_7] =KEY_PAD_7;
  762. s_pVirtualKeyToButtonCode[CELL_KEYC_KPAD_8] =KEY_PAD_8;
  763. s_pVirtualKeyToButtonCode[CELL_KEYC_KPAD_9] =KEY_PAD_9;
  764. s_pVirtualKeyToButtonCode[CELL_KEYC_KPAD_SLASH] =KEY_PAD_DIVIDE;
  765. s_pVirtualKeyToButtonCode[CELL_KEYC_KPAD_ASTERISK] =KEY_PAD_MULTIPLY;
  766. s_pVirtualKeyToButtonCode[CELL_KEYC_KPAD_MINUS] =KEY_PAD_MINUS;
  767. s_pVirtualKeyToButtonCode[CELL_KEYC_KPAD_PLUS] =KEY_PAD_PLUS;
  768. s_pVirtualKeyToButtonCode[CELL_KEYC_KPAD_ENTER] =KEY_PAD_ENTER;
  769. s_pVirtualKeyToButtonCode[CELL_KEYC_KPAD_PERIOD] =KEY_PAD_DECIMAL;
  770. #elif !defined( PLATFORM_POSIX )
  771. s_pVirtualKeyToButtonCode[VK_NUMPAD0] =KEY_PAD_0;
  772. s_pVirtualKeyToButtonCode[VK_NUMPAD1] =KEY_PAD_1;
  773. s_pVirtualKeyToButtonCode[VK_NUMPAD2] =KEY_PAD_2;
  774. s_pVirtualKeyToButtonCode[VK_NUMPAD3] =KEY_PAD_3;
  775. s_pVirtualKeyToButtonCode[VK_NUMPAD4] =KEY_PAD_4;
  776. s_pVirtualKeyToButtonCode[VK_NUMPAD5] =KEY_PAD_5;
  777. s_pVirtualKeyToButtonCode[VK_NUMPAD6] =KEY_PAD_6;
  778. s_pVirtualKeyToButtonCode[VK_NUMPAD7] =KEY_PAD_7;
  779. s_pVirtualKeyToButtonCode[VK_NUMPAD8] =KEY_PAD_8;
  780. s_pVirtualKeyToButtonCode[VK_NUMPAD9] =KEY_PAD_9;
  781. s_pVirtualKeyToButtonCode[VK_DIVIDE] =KEY_PAD_DIVIDE;
  782. s_pVirtualKeyToButtonCode[VK_MULTIPLY] =KEY_PAD_MULTIPLY;
  783. s_pVirtualKeyToButtonCode[VK_SUBTRACT] =KEY_PAD_MINUS;
  784. s_pVirtualKeyToButtonCode[VK_ADD] =KEY_PAD_PLUS;
  785. s_pVirtualKeyToButtonCode[VK_RETURN] =KEY_PAD_ENTER;
  786. s_pVirtualKeyToButtonCode[VK_DECIMAL] =KEY_PAD_DECIMAL;
  787. #endif
  788. #if defined ( _PS3 )
  789. s_pVirtualKeyToButtonCode[CELL_KEYC_LEFT_BRACKET_101] =KEY_LBRACKET;
  790. s_pVirtualKeyToButtonCode[CELL_KEYC_RIGHT_BRACKET_101] =KEY_RBRACKET;
  791. s_pVirtualKeyToButtonCode[CELL_KEYC_SEMICOLON] =KEY_SEMICOLON;
  792. s_pVirtualKeyToButtonCode[CELL_KEYC_QUOTATION_101] =KEY_APOSTROPHE;
  793. s_pVirtualKeyToButtonCode[CELL_KEYC_106_KANJI] =KEY_BACKQUOTE;
  794. s_pVirtualKeyToButtonCode[CELL_KEYC_COMMA] =KEY_COMMA;
  795. s_pVirtualKeyToButtonCode[CELL_KEYC_PERIOD] =KEY_PERIOD;
  796. s_pVirtualKeyToButtonCode[CELL_KEYC_SLASH] =KEY_SLASH;
  797. s_pVirtualKeyToButtonCode[CELL_KEYC_BACKSLASH_101] =KEY_BACKSLASH;
  798. s_pVirtualKeyToButtonCode[CELL_KEYC_MINUS] =KEY_MINUS;
  799. s_pVirtualKeyToButtonCode[CELL_KEYC_EQUAL_101] =KEY_EQUAL;
  800. #else
  801. s_pVirtualKeyToButtonCode[0xdb] =KEY_LBRACKET;
  802. s_pVirtualKeyToButtonCode[0xdd] =KEY_RBRACKET;
  803. s_pVirtualKeyToButtonCode[0xba] =KEY_SEMICOLON;
  804. s_pVirtualKeyToButtonCode[0xde] =KEY_APOSTROPHE;
  805. s_pVirtualKeyToButtonCode[0xc0] =KEY_BACKQUOTE;
  806. s_pVirtualKeyToButtonCode[0xbc] =KEY_COMMA;
  807. s_pVirtualKeyToButtonCode[0xbe] =KEY_PERIOD;
  808. s_pVirtualKeyToButtonCode[0xbf] =KEY_SLASH;
  809. s_pVirtualKeyToButtonCode[0xdc] =KEY_BACKSLASH;
  810. s_pVirtualKeyToButtonCode[0xbd] =KEY_MINUS;
  811. s_pVirtualKeyToButtonCode[0xbb] =KEY_EQUAL;
  812. #endif
  813. #if defined ( _PS3 )
  814. s_pVirtualKeyToButtonCode[CELL_KEYC_ENTER] =KEY_ENTER;
  815. s_pVirtualKeyToButtonCode[CELL_KEYC_SPACE] =KEY_SPACE;
  816. s_pVirtualKeyToButtonCode[CELL_KEYC_BS] =KEY_BACKSPACE;
  817. s_pVirtualKeyToButtonCode[CELL_KEYC_TAB] =KEY_TAB;
  818. s_pVirtualKeyToButtonCode[CELL_KEYC_CAPS_LOCK] =KEY_CAPSLOCK;
  819. s_pVirtualKeyToButtonCode[CELL_KEYC_NUM_LOCK] =KEY_NUMLOCK;
  820. s_pVirtualKeyToButtonCode[CELL_KEYC_ESC] =KEY_ESCAPE;
  821. s_pVirtualKeyToButtonCode[CELL_KEYC_SCROLL_LOCK] =KEY_SCROLLLOCK;
  822. s_pVirtualKeyToButtonCode[CELL_KEYC_INSERT] =KEY_INSERT;
  823. s_pVirtualKeyToButtonCode[CELL_KEYC_DELETE] =KEY_DELETE;
  824. s_pVirtualKeyToButtonCode[CELL_KEYC_HOME] =KEY_HOME;
  825. s_pVirtualKeyToButtonCode[CELL_KEYC_END] =KEY_END;
  826. s_pVirtualKeyToButtonCode[CELL_KEYC_PAGE_UP] =KEY_PAGEUP;
  827. s_pVirtualKeyToButtonCode[CELL_KEYC_PAGE_DOWN] =KEY_PAGEDOWN;
  828. s_pVirtualKeyToButtonCode[CELL_KEYC_PAUSE] =KEY_BREAK;
  829. s_pVirtualKeyToButtonCode[CELL_KEYC_APPLICATION] =KEY_APP;
  830. s_pVirtualKeyToButtonCode[CELL_KEYC_UP_ARROW] =KEY_UP;
  831. s_pVirtualKeyToButtonCode[CELL_KEYC_LEFT_ARROW] =KEY_LEFT;
  832. s_pVirtualKeyToButtonCode[CELL_KEYC_DOWN_ARROW] =KEY_DOWN;
  833. s_pVirtualKeyToButtonCode[CELL_KEYC_RIGHT_ARROW] =KEY_RIGHT;
  834. s_pVirtualKeyToButtonCode[CELL_KEYC_F1] =KEY_F1;
  835. s_pVirtualKeyToButtonCode[CELL_KEYC_F2] =KEY_F2;
  836. s_pVirtualKeyToButtonCode[CELL_KEYC_F3] =KEY_F3;
  837. s_pVirtualKeyToButtonCode[CELL_KEYC_F4] =KEY_F4;
  838. s_pVirtualKeyToButtonCode[CELL_KEYC_F5] =KEY_F5;
  839. s_pVirtualKeyToButtonCode[CELL_KEYC_F6] =KEY_F6;
  840. s_pVirtualKeyToButtonCode[CELL_KEYC_F7] =KEY_F7;
  841. s_pVirtualKeyToButtonCode[CELL_KEYC_F8] =KEY_F8;
  842. s_pVirtualKeyToButtonCode[CELL_KEYC_F9] =KEY_F9;
  843. s_pVirtualKeyToButtonCode[CELL_KEYC_F10] =KEY_F10;
  844. s_pVirtualKeyToButtonCode[CELL_KEYC_F11] =KEY_F11;
  845. s_pVirtualKeyToButtonCode[CELL_KEYC_F12] =KEY_F12;
  846. #elif !defined( PLATFORM_POSIX )
  847. s_pVirtualKeyToButtonCode[VK_RETURN] =KEY_ENTER;
  848. s_pVirtualKeyToButtonCode[VK_SPACE] =KEY_SPACE;
  849. s_pVirtualKeyToButtonCode[VK_BACK] =KEY_BACKSPACE;
  850. s_pVirtualKeyToButtonCode[VK_TAB] =KEY_TAB;
  851. s_pVirtualKeyToButtonCode[VK_CAPITAL] =KEY_CAPSLOCK;
  852. s_pVirtualKeyToButtonCode[VK_NUMLOCK] =KEY_NUMLOCK;
  853. s_pVirtualKeyToButtonCode[VK_ESCAPE] =KEY_ESCAPE;
  854. s_pVirtualKeyToButtonCode[VK_SCROLL] =KEY_SCROLLLOCK;
  855. s_pVirtualKeyToButtonCode[VK_INSERT] =KEY_INSERT;
  856. s_pVirtualKeyToButtonCode[VK_DELETE] =KEY_DELETE;
  857. s_pVirtualKeyToButtonCode[VK_HOME] =KEY_HOME;
  858. s_pVirtualKeyToButtonCode[VK_END] =KEY_END;
  859. s_pVirtualKeyToButtonCode[VK_PRIOR] =KEY_PAGEUP;
  860. s_pVirtualKeyToButtonCode[VK_NEXT] =KEY_PAGEDOWN;
  861. s_pVirtualKeyToButtonCode[VK_PAUSE] =KEY_BREAK;
  862. s_pVirtualKeyToButtonCode[VK_SHIFT] =KEY_RSHIFT;
  863. s_pVirtualKeyToButtonCode[VK_SHIFT] =KEY_LSHIFT; // SHIFT -> left SHIFT
  864. s_pVirtualKeyToButtonCode[VK_MENU] =KEY_RALT;
  865. s_pVirtualKeyToButtonCode[VK_MENU] =KEY_LALT; // ALT -> left ALT
  866. s_pVirtualKeyToButtonCode[VK_CONTROL] =KEY_RCONTROL;
  867. s_pVirtualKeyToButtonCode[VK_CONTROL] =KEY_LCONTROL; // CTRL -> left CTRL
  868. s_pVirtualKeyToButtonCode[VK_LWIN] =KEY_LWIN;
  869. s_pVirtualKeyToButtonCode[VK_RWIN] =KEY_RWIN;
  870. s_pVirtualKeyToButtonCode[VK_APPS] =KEY_APP;
  871. s_pVirtualKeyToButtonCode[VK_UP] =KEY_UP;
  872. s_pVirtualKeyToButtonCode[VK_LEFT] =KEY_LEFT;
  873. s_pVirtualKeyToButtonCode[VK_DOWN] =KEY_DOWN;
  874. s_pVirtualKeyToButtonCode[VK_RIGHT] =KEY_RIGHT;
  875. s_pVirtualKeyToButtonCode[VK_F1] =KEY_F1;
  876. s_pVirtualKeyToButtonCode[VK_F2] =KEY_F2;
  877. s_pVirtualKeyToButtonCode[VK_F3] =KEY_F3;
  878. s_pVirtualKeyToButtonCode[VK_F4] =KEY_F4;
  879. s_pVirtualKeyToButtonCode[VK_F5] =KEY_F5;
  880. s_pVirtualKeyToButtonCode[VK_F6] =KEY_F6;
  881. s_pVirtualKeyToButtonCode[VK_F7] =KEY_F7;
  882. s_pVirtualKeyToButtonCode[VK_F8] =KEY_F8;
  883. s_pVirtualKeyToButtonCode[VK_F9] =KEY_F9;
  884. s_pVirtualKeyToButtonCode[VK_F10] =KEY_F10;
  885. s_pVirtualKeyToButtonCode[VK_F11] =KEY_F11;
  886. s_pVirtualKeyToButtonCode[VK_F12] =KEY_F12;
  887. #endif
  888. // init the xkey translation table
  889. #if !defined( PLATFORM_POSIX ) || defined( _GAMECONSOLE ) || defined( _OSX )
  890. s_pXKeyTrans[XK_NULL] = KEY_NONE;
  891. s_pXKeyTrans[XK_BUTTON_UP] = KEY_XBUTTON_UP;
  892. s_pXKeyTrans[XK_BUTTON_DOWN] = KEY_XBUTTON_DOWN;
  893. s_pXKeyTrans[XK_BUTTON_LEFT] = KEY_XBUTTON_LEFT;
  894. s_pXKeyTrans[XK_BUTTON_RIGHT] = KEY_XBUTTON_RIGHT;
  895. s_pXKeyTrans[XK_BUTTON_START] = KEY_XBUTTON_START;
  896. s_pXKeyTrans[XK_BUTTON_BACK] = KEY_XBUTTON_BACK;
  897. s_pXKeyTrans[XK_BUTTON_STICK1] = KEY_XBUTTON_STICK1;
  898. s_pXKeyTrans[XK_BUTTON_STICK2] = KEY_XBUTTON_STICK2;
  899. s_pXKeyTrans[XK_BUTTON_A] = KEY_XBUTTON_A;
  900. s_pXKeyTrans[XK_BUTTON_B] = KEY_XBUTTON_B;
  901. s_pXKeyTrans[XK_BUTTON_X] = KEY_XBUTTON_X;
  902. s_pXKeyTrans[XK_BUTTON_Y] = KEY_XBUTTON_Y;
  903. s_pXKeyTrans[XK_BUTTON_LEFT_SHOULDER] = KEY_XBUTTON_LEFT_SHOULDER;
  904. s_pXKeyTrans[XK_BUTTON_RIGHT_SHOULDER] = KEY_XBUTTON_RIGHT_SHOULDER;
  905. s_pXKeyTrans[XK_BUTTON_LTRIGGER] = KEY_XBUTTON_LTRIGGER;
  906. s_pXKeyTrans[XK_BUTTON_RTRIGGER] = KEY_XBUTTON_RTRIGGER;
  907. s_pXKeyTrans[XK_STICK1_UP] = KEY_XSTICK1_UP;
  908. s_pXKeyTrans[XK_STICK1_DOWN] = KEY_XSTICK1_DOWN;
  909. s_pXKeyTrans[XK_STICK1_LEFT] = KEY_XSTICK1_LEFT;
  910. s_pXKeyTrans[XK_STICK1_RIGHT] = KEY_XSTICK1_RIGHT;
  911. s_pXKeyTrans[XK_STICK2_UP] = KEY_XSTICK2_UP;
  912. s_pXKeyTrans[XK_STICK2_DOWN] = KEY_XSTICK2_DOWN;
  913. s_pXKeyTrans[XK_STICK2_LEFT] = KEY_XSTICK2_LEFT;
  914. s_pXKeyTrans[XK_STICK2_RIGHT] = KEY_XSTICK2_RIGHT;
  915. s_pXKeyTrans[XK_BUTTON_INACTIVE_START] = KEY_XBUTTON_INACTIVE_START;
  916. s_pXKeyTrans[XK_BUTTON_FIREMODE_SELECTOR_1] = KEY_XBUTTON_FIREMODE_SELECTOR_1;
  917. s_pXKeyTrans[XK_BUTTON_FIREMODE_SELECTOR_2] = KEY_XBUTTON_FIREMODE_SELECTOR_2;
  918. s_pXKeyTrans[XK_BUTTON_FIREMODE_SELECTOR_3] = KEY_XBUTTON_FIREMODE_SELECTOR_3;
  919. s_pXKeyTrans[XK_BUTTON_RELOAD] = KEY_XBUTTON_RELOAD;
  920. s_pXKeyTrans[XK_BUTTON_TRIGGER] = KEY_XBUTTON_TRIGGER;
  921. s_pXKeyTrans[XK_BUTTON_PUMP_ACTION] = KEY_XBUTTON_PUMP_ACTION;
  922. s_pXKeyTrans[XK_XBUTTON_ROLL_RIGHT] = KEY_XBUTTON_ROLL_RIGHT;
  923. s_pXKeyTrans[XK_XBUTTON_ROLL_LEFT] = KEY_XBUTTON_ROLL_LEFT;
  924. #endif // PLATFORM_POSIX
  925. // create reverse table engine to virtual
  926. for ( int i = 0; i < ARRAYSIZE( s_pVirtualKeyToButtonCode ); i++ )
  927. {
  928. s_pButtonCodeToVirtual[ s_pVirtualKeyToButtonCode[i] ] = i;
  929. }
  930. s_pButtonCodeToVirtual[0] = 0;
  931. s_pSKeytoButtonCode[SK_NULL] = KEY_NONE;
  932. s_pSKeytoButtonCode[SK_BUTTON_A] = STEAMCONTROLLER_A;
  933. s_pSKeytoButtonCode[SK_BUTTON_B] = STEAMCONTROLLER_B;
  934. s_pSKeytoButtonCode[SK_BUTTON_X] = STEAMCONTROLLER_X;
  935. s_pSKeytoButtonCode[SK_BUTTON_Y] = STEAMCONTROLLER_Y;
  936. s_pSKeytoButtonCode[SK_BUTTON_UP] = STEAMCONTROLLER_DPAD_UP;
  937. s_pSKeytoButtonCode[SK_BUTTON_RIGHT] = STEAMCONTROLLER_DPAD_RIGHT;
  938. s_pSKeytoButtonCode[SK_BUTTON_DOWN] = STEAMCONTROLLER_DPAD_DOWN;
  939. s_pSKeytoButtonCode[SK_BUTTON_LEFT] = STEAMCONTROLLER_DPAD_LEFT;
  940. s_pSKeytoButtonCode[SK_BUTTON_LEFT_BUMPER] = STEAMCONTROLLER_LEFT_BUMPER;
  941. s_pSKeytoButtonCode[SK_BUTTON_RIGHT_BUMPER] = STEAMCONTROLLER_RIGHT_BUMPER;
  942. s_pSKeytoButtonCode[SK_BUTTON_LEFT_TRIGGER] = STEAMCONTROLLER_LEFT_TRIGGER;
  943. s_pSKeytoButtonCode[SK_BUTTON_RIGHT_TRIGGER] = STEAMCONTROLLER_RIGHT_TRIGGER;
  944. s_pSKeytoButtonCode[SK_BUTTON_LEFT_GRIP] = STEAMCONTROLLER_LEFT_GRIP;
  945. s_pSKeytoButtonCode[SK_BUTTON_RIGHT_GRIP] = STEAMCONTROLLER_RIGHT_GRIP;
  946. s_pSKeytoButtonCode[SK_BUTTON_LPAD_TOUCH] = STEAMCONTROLLER_LEFT_PAD_FINGERDOWN;
  947. s_pSKeytoButtonCode[SK_BUTTON_RPAD_TOUCH] = STEAMCONTROLLER_RIGHT_PAD_FINGERDOWN;
  948. s_pSKeytoButtonCode[SK_BUTTON_LPAD_CLICK] = STEAMCONTROLLER_LEFT_PAD_CLICK;
  949. s_pSKeytoButtonCode[SK_BUTTON_RPAD_CLICK] = STEAMCONTROLLER_RIGHT_PAD_CLICK;
  950. s_pSKeytoButtonCode[SK_BUTTON_LPAD_UP] = STEAMCONTROLLER_LEFT_PAD_UP;
  951. s_pSKeytoButtonCode[SK_BUTTON_LPAD_RIGHT] = STEAMCONTROLLER_LEFT_PAD_RIGHT;
  952. s_pSKeytoButtonCode[SK_BUTTON_LPAD_DOWN] = STEAMCONTROLLER_LEFT_PAD_DOWN;
  953. s_pSKeytoButtonCode[SK_BUTTON_LPAD_LEFT] = STEAMCONTROLLER_LEFT_PAD_LEFT;
  954. s_pSKeytoButtonCode[SK_BUTTON_RPAD_UP] = STEAMCONTROLLER_RIGHT_PAD_UP;
  955. s_pSKeytoButtonCode[SK_BUTTON_RPAD_RIGHT] = STEAMCONTROLLER_RIGHT_PAD_RIGHT;
  956. s_pSKeytoButtonCode[SK_BUTTON_RPAD_DOWN] = STEAMCONTROLLER_RIGHT_PAD_DOWN;
  957. s_pSKeytoButtonCode[SK_BUTTON_RPAD_LEFT] = STEAMCONTROLLER_RIGHT_PAD_LEFT;
  958. s_pSKeytoButtonCode[SK_BUTTON_SELECT] = STEAMCONTROLLER_SELECT;
  959. s_pSKeytoButtonCode[SK_BUTTON_START] = STEAMCONTROLLER_START;
  960. s_pSKeytoButtonCode[SK_BUTTON_STEAM] = STEAMCONTROLLER_STEAM;
  961. s_pSKeytoButtonCode[SK_BUTTON_INACTIVE_START] = STEAMCONTROLLER_INACTIVE_START;
  962. }
  963. ButtonCode_t ButtonCode_VirtualKeyToButtonCode( int keyCode )
  964. {
  965. if ( keyCode < 0 || keyCode >= sizeof( s_pVirtualKeyToButtonCode ) / sizeof( s_pVirtualKeyToButtonCode[0] ) )
  966. {
  967. Assert( false );
  968. return KEY_NONE;
  969. }
  970. return s_pVirtualKeyToButtonCode[keyCode];
  971. }
  972. int ButtonCode_ButtonCodeToVirtualKey( ButtonCode_t code )
  973. {
  974. return s_pButtonCodeToVirtual[code];
  975. }
  976. ButtonCode_t ButtonCode_XKeyToButtonCode( int nPort, int keyCode )
  977. {
  978. #if !defined( PLATFORM_POSIX ) || defined( _GAMECONSOLE ) || defined( _OSX )
  979. if ( keyCode < 0 || keyCode >= sizeof( s_pXKeyTrans ) / sizeof( s_pXKeyTrans[0] ) )
  980. {
  981. Assert( false );
  982. return KEY_NONE;
  983. }
  984. ButtonCode_t code = s_pXKeyTrans[keyCode];
  985. if ( IsJoystickButtonCode( code ) )
  986. {
  987. int nOffset = code - JOYSTICK_FIRST_BUTTON;
  988. return JOYSTICK_BUTTON( nPort, nOffset );
  989. }
  990. if ( IsJoystickPOVCode( code ) )
  991. {
  992. int nOffset = code - JOYSTICK_FIRST_POV_BUTTON;
  993. return JOYSTICK_POV_BUTTON( nPort, nOffset );
  994. }
  995. if ( IsJoystickAxisCode( code ) )
  996. {
  997. int nOffset = code - JOYSTICK_FIRST_AXIS_BUTTON;
  998. return JOYSTICK_AXIS_BUTTON( nPort, nOffset );
  999. }
  1000. return code;
  1001. #else // PLATFORM_POSIX
  1002. return KEY_NONE;
  1003. #endif // PLATFORM_POSIX
  1004. }
  1005. ButtonCode_t ButtonCode_SKeyToButtonCode( int nPort, int keyCode )
  1006. {
  1007. #if !defined( _GAMECONSOLE )
  1008. if ( keyCode < 0 || keyCode >= sizeof( s_pSKeytoButtonCode ) / sizeof( s_pSKeytoButtonCode[0] ) )
  1009. {
  1010. Assert( false );
  1011. return KEY_NONE;
  1012. }
  1013. ButtonCode_t code = s_pSKeytoButtonCode[keyCode];
  1014. // if ( IsSteamControllerCode( code ) )
  1015. // {
  1016. // // Need Per Controller Offset here.
  1017. // return code;
  1018. // }
  1019. if ( IsSteamControllerButtonCode( code ) )
  1020. {
  1021. int nOffset = code - STEAMCONTROLLER_FIRST_BUTTON;
  1022. return STEAMCONTROLLER_BUTTON( nPort, nOffset );
  1023. }
  1024. if ( IsSteamControllerAxisCode( code ) )
  1025. {
  1026. int nOffset = code - STEAMCONTROLLER_FIRST_AXIS_BUTTON;
  1027. return STEAMCONTROLLER_AXIS_BUTTON( nPort, nOffset );
  1028. }
  1029. return code;
  1030. #else // _GAMECONSOLE
  1031. return KEY_NONE;
  1032. #endif // _GAMECONSOLE
  1033. }
  1034. // Convert back + forth between ButtonCode/AnalogCode + strings
  1035. const char *ButtonCode_ButtonCodeToString( ButtonCode_t code, bool bXController )
  1036. {
  1037. #if !defined ( _GAMECONSOLE )
  1038. if ( bXController )
  1039. {
  1040. if ( IsJoystickButtonCode( code ) )
  1041. {
  1042. int offset = ( code - JOYSTICK_FIRST_BUTTON ) % JOYSTICK_MAX_BUTTON_COUNT;
  1043. return s_pXControllerButtonCodeNames[ offset ];
  1044. }
  1045. if ( IsJoystickPOVCode( code ) )
  1046. {
  1047. int offset = ( code - JOYSTICK_FIRST_POV_BUTTON ) % JOYSTICK_POV_BUTTON_COUNT;
  1048. return s_pXControllerButtonCodeNames[ MAX_JOYSTICKS * JOYSTICK_MAX_BUTTON_COUNT + offset ];
  1049. }
  1050. if ( IsJoystickAxisCode( code ) )
  1051. {
  1052. int offset = ( code - JOYSTICK_FIRST_AXIS_BUTTON ) % JOYSTICK_AXIS_BUTTON_COUNT;
  1053. return s_pXControllerButtonCodeNames[ MAX_JOYSTICKS * ( JOYSTICK_POV_BUTTON_COUNT + JOYSTICK_MAX_BUTTON_COUNT ) + offset ];
  1054. }
  1055. }
  1056. #endif
  1057. return s_pButtonCodeName[ code ];
  1058. }
  1059. const char *AnalogCode_AnalogCodeToString( AnalogCode_t code )
  1060. {
  1061. return s_pAnalogCodeName[ code ];
  1062. }
  1063. ButtonCode_t ButtonCode_StringToButtonCode( const char *pString, bool bXController )
  1064. {
  1065. if ( !pString || !pString[0] )
  1066. return BUTTON_CODE_INVALID;
  1067. // Backward compat for screwed up previous joystick button names
  1068. if ( !Q_strnicmp( pString, "aux", 3 ) )
  1069. {
  1070. int nIndex = atoi( &pString[3] );
  1071. if ( nIndex < 29 )
  1072. return JOYSTICK_BUTTON( 0, nIndex );
  1073. if ( ( nIndex >= 29 ) && ( nIndex <= 32 ) )
  1074. return JOYSTICK_POV_BUTTON( 0, nIndex - 29 );
  1075. return BUTTON_CODE_INVALID;
  1076. }
  1077. #if defined(OSX)
  1078. // map "l_win" to the LWIN key on OSX (it appears in the table as "command" )
  1079. if ( !Q_stricmp( pString, "lwin" ) )
  1080. #else
  1081. // map "COMMAND" to the LWIN key on non-OSX
  1082. if ( !Q_stricmp( pString, "command" ) )
  1083. #endif
  1084. {
  1085. return KEY_LWIN;
  1086. }
  1087. #if defined( _PS3 )
  1088. // For PS3, we want to check against specific PS3 button code names.
  1089. for ( int i = 0; i < BUTTON_CODE_LAST; ++i )
  1090. {
  1091. if ( !Q_stricmp( s_pPS3ButtonCodeName[i], pString ) )
  1092. return (ButtonCode_t)i;
  1093. }
  1094. #endif
  1095. for ( int i = 0; i < BUTTON_CODE_LAST; ++i )
  1096. {
  1097. if ( !Q_stricmp( s_pButtonCodeName[i], pString ) )
  1098. return (ButtonCode_t)i;
  1099. }
  1100. #if !defined ( _GAMECONSOLE )
  1101. if ( bXController )
  1102. {
  1103. for ( int i = 0; i < ARRAYSIZE(s_pXControllerButtonCodeNames); ++i )
  1104. {
  1105. if ( !Q_stricmp( s_pXControllerButtonCodeNames[i], pString ) )
  1106. return (ButtonCode_t)(JOYSTICK_FIRST_BUTTON + i);
  1107. }
  1108. }
  1109. #endif
  1110. return BUTTON_CODE_INVALID;
  1111. }
  1112. AnalogCode_t AnalogCode_StringToAnalogCode( const char *pString )
  1113. {
  1114. if ( !pString || !pString[0] )
  1115. return ANALOG_CODE_INVALID;
  1116. for ( int i = 0; i < ANALOG_CODE_LAST; ++i )
  1117. {
  1118. if ( !Q_stricmp( s_pAnalogCodeName[i], pString ) )
  1119. return (AnalogCode_t)i;
  1120. }
  1121. return ANALOG_CODE_INVALID;
  1122. }
  1123. ButtonCode_t ButtonCode_ScanCodeToButtonCode( int lParam )
  1124. {
  1125. int nScanCode = ( lParam >> 16 ) & 0xFF;
  1126. if ( nScanCode > 127 )
  1127. return KEY_NONE;
  1128. ButtonCode_t result = s_pScanToButtonCode[nScanCode];
  1129. bool bIsExtended = ( lParam & ( 1 << 24 ) ) != 0;
  1130. if ( !bIsExtended )
  1131. {
  1132. switch ( result )
  1133. {
  1134. case KEY_HOME:
  1135. return KEY_PAD_7;
  1136. case KEY_UP:
  1137. return KEY_PAD_8;
  1138. case KEY_PAGEUP:
  1139. return KEY_PAD_9;
  1140. case KEY_LEFT:
  1141. return KEY_PAD_4;
  1142. case KEY_RIGHT:
  1143. return KEY_PAD_6;
  1144. case KEY_END:
  1145. return KEY_PAD_1;
  1146. case KEY_DOWN:
  1147. return KEY_PAD_2;
  1148. case KEY_PAGEDOWN:
  1149. return KEY_PAD_3;
  1150. case KEY_INSERT:
  1151. return KEY_PAD_0;
  1152. case KEY_DELETE:
  1153. return KEY_PAD_DECIMAL;
  1154. default:
  1155. break;
  1156. }
  1157. }
  1158. else
  1159. {
  1160. switch ( result )
  1161. {
  1162. case KEY_ENTER:
  1163. return KEY_PAD_ENTER;
  1164. case KEY_LALT:
  1165. return KEY_RALT;
  1166. case KEY_LCONTROL:
  1167. return KEY_RCONTROL;
  1168. case KEY_SLASH:
  1169. return KEY_PAD_DIVIDE;
  1170. case KEY_CAPSLOCK:
  1171. return KEY_PAD_PLUS;
  1172. }
  1173. }
  1174. return result;
  1175. }
  1176. //-----------------------------------------------------------------------------
  1177. // Update scan codes for foreign keyboards
  1178. //-----------------------------------------------------------------------------
  1179. void ButtonCode_UpdateScanCodeLayout( )
  1180. {
  1181. // reset the keyboard
  1182. memcpy( s_pScanToButtonCode, s_pScanToButtonCode_QWERTY, sizeof(s_pScanToButtonCode) );
  1183. #if !defined( _GAMECONSOLE ) && !defined( PLATFORM_POSIX )
  1184. // fix up keyboard layout for other languages
  1185. HKL currentKb = ::GetKeyboardLayout( 0 );
  1186. HKL englishKb = ::LoadKeyboardLayout("00000409", 0);
  1187. if (englishKb && englishKb != currentKb)
  1188. {
  1189. for ( int i = 0; i < ARRAYSIZE(s_pScanToButtonCode); i++ )
  1190. {
  1191. // take the english/QWERTY
  1192. ButtonCode_t code = s_pScanToButtonCode_QWERTY[ i ];
  1193. // only remap printable keys
  1194. if ( code != KEY_NONE && code != KEY_BACKQUOTE && ( IsAlphaNumeric( code ) || IsPunctuation( code ) ) )
  1195. {
  1196. // get it's virtual key based on the old layout
  1197. int vk = ::MapVirtualKeyEx( i, 1, englishKb );
  1198. // turn in into a scancode on the new layout
  1199. int newScanCode = ::MapVirtualKeyEx( vk, 0, currentKb );
  1200. // strip off any high bits
  1201. newScanCode &= 0x0000007F;
  1202. // set in the new layout
  1203. s_pScanToButtonCode[newScanCode] = code;
  1204. }
  1205. }
  1206. }
  1207. s_pScanToButtonCode[0] = KEY_NONE;
  1208. #endif
  1209. }
  1210. //-----------------------------------------------------------------------------
  1211. // Purpose: Updates the current keyboard layout
  1212. //-----------------------------------------------------------------------------
  1213. CON_COMMAND( key_updatelayout, "Updates game keyboard layout to current windows keyboard setting." )
  1214. {
  1215. ButtonCode_UpdateScanCodeLayout();
  1216. }