winInput.cc 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2013 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #include "platformWin32/platformWin32.h"
  23. #include "platform/platformInput.h"
  24. #include "platform/platformVideo.h"
  25. #include "platformWin32/winDirectInput.h"
  26. #include "platform/event.h"
  27. #include "console/console.h"
  28. #include "platform/platformInput_ScriptBinding.h"
  29. #include "winInput_ScriptBinding.h"
  30. // Static class variables:
  31. InputManager* Input::smManager;
  32. bool Input::smActive;
  33. CursorManager* Input::smCursorManager = 0; //*** DAW: Added
  34. U8 Input::smModifierKeys; //*** DAW: Added
  35. bool Input::smLastKeyboardActivated;
  36. bool Input::smLastMouseActivated;
  37. bool Input::smLastJoystickActivated;
  38. static void fillAsciiTable();
  39. //------------------------------------------------------------------------------
  40. //
  41. // This function gets the standard ASCII code corresponding to our key code
  42. // and the existing modifier key state.
  43. //
  44. //------------------------------------------------------------------------------
  45. struct AsciiData
  46. {
  47. struct KeyData
  48. {
  49. U16 ascii;
  50. bool isDeadChar;
  51. };
  52. KeyData upper;
  53. KeyData lower;
  54. KeyData goofy;
  55. };
  56. #define NUM_KEYS ( KEY_OEM_102 + 1 )
  57. #define KEY_FIRST KEY_ESCAPE
  58. static AsciiData AsciiTable[NUM_KEYS];
  59. //------------------------------------------------------------------------------
  60. void Input::init()
  61. {
  62. Con::printSeparator();
  63. Con::printf( "Input Initialization:" );
  64. destroy();
  65. smActive = false;
  66. smLastKeyboardActivated = true;
  67. smLastMouseActivated = true;
  68. smLastJoystickActivated = true;
  69. smManager = new DInputManager;
  70. if (!smManager->enable())
  71. {
  72. Con::printf(" DirectInput not enabled.");
  73. delete smManager;
  74. smManager = NULL;
  75. }
  76. else
  77. {
  78. DInputManager::init();
  79. Con::printf(" DirectInput enabled.");
  80. }
  81. // Startup the Cursor Manager
  82. if(!smCursorManager)
  83. {
  84. smCursorManager = new CursorManager();
  85. if(smCursorManager)
  86. {
  87. // Add the arrow cursor to the stack
  88. smCursorManager->pushCursor(CursorManager::curArrow);
  89. }
  90. else
  91. {
  92. Con::printf(" Cursor Manager not enabled.");
  93. }
  94. }
  95. // Init the current modifier keys
  96. setModifierKeys(0);
  97. fillAsciiTable();
  98. Con::printf( "" );
  99. }
  100. //------------------------------------------------------------------------------
  101. static void fillAsciiTable()
  102. {
  103. //HKL layout = GetKeyboardLayout( 0 );
  104. U8 state[256];
  105. U16 ascii[2];
  106. U32 dikCode, vKeyCode, keyCode;
  107. S32 result;
  108. dMemset( &AsciiTable, 0, sizeof( AsciiTable ) );
  109. dMemset( &state, 0, sizeof( state ) );
  110. for ( keyCode = KEY_FIRST; keyCode < NUM_KEYS; keyCode++ )
  111. {
  112. ascii[0] = ascii[1] = 0;
  113. dikCode = Key_to_DIK( keyCode );
  114. if ( dikCode )
  115. {
  116. //vKeyCode = MapVirtualKeyEx( dikCode, 1, layout );
  117. vKeyCode = MapVirtualKey( dikCode, 1 );
  118. // Lower case:
  119. ascii[0] = ascii[1] = 0;
  120. //result = ToAsciiEx( vKeyCode, dikCode, state, ascii, 0, layout );
  121. result = ToAscii( vKeyCode, dikCode, state, ascii, 0 );
  122. if ( result == 2 )
  123. AsciiTable[keyCode].lower.ascii = ascii[1] ? ascii[1] : ( ascii[0] >> 8 );
  124. else if ( result == 1 )
  125. AsciiTable[keyCode].lower.ascii = ascii[0];
  126. else if ( result < 0 )
  127. {
  128. AsciiTable[keyCode].lower.ascii = ascii[0];
  129. AsciiTable[keyCode].lower.isDeadChar = true;
  130. // Need to clear the dead character from the keyboard layout:
  131. //ToAsciiEx( vKeyCode, dikCode, state, ascii, 0, layout );
  132. ToAscii( vKeyCode, dikCode, state, ascii, 0 );
  133. }
  134. // Upper case:
  135. ascii[0] = ascii[1] = 0;
  136. state[VK_SHIFT] = 0x80;
  137. //result = ToAsciiEx( vKeyCode, dikCode, state, ascii, 0, layout );
  138. result = ToAscii( vKeyCode, dikCode, state, ascii, 0 );
  139. if ( result == 2 )
  140. AsciiTable[keyCode].upper.ascii = ascii[1] ? ascii[1] : ( ascii[0] >> 8 );
  141. else if ( result == 1 )
  142. AsciiTable[keyCode].upper.ascii = ascii[0];
  143. else if ( result < 0 )
  144. {
  145. AsciiTable[keyCode].upper.ascii = ascii[0];
  146. AsciiTable[keyCode].upper.isDeadChar = true;
  147. // Need to clear the dead character from the keyboard layout:
  148. //ToAsciiEx( vKeyCode, dikCode, state, ascii, 0, layout );
  149. ToAscii( vKeyCode, dikCode, state, ascii, 0 );
  150. }
  151. state[VK_SHIFT] = 0;
  152. // Foreign mod case:
  153. ascii[0] = ascii[1] = 0;
  154. state[VK_CONTROL] = 0x80;
  155. state[VK_MENU] = 0x80;
  156. //result = ToAsciiEx( vKeyCode, dikCode, state, ascii, 0, layout );
  157. result = ToAscii( vKeyCode, dikCode, state, ascii, 0 );
  158. if ( result == 2 )
  159. AsciiTable[keyCode].goofy.ascii = ascii[1] ? ascii[1] : ( ascii[0] >> 8 );
  160. else if ( result == 1 )
  161. AsciiTable[keyCode].goofy.ascii = ascii[0];
  162. else if ( result < 0 )
  163. {
  164. AsciiTable[keyCode].goofy.ascii = ascii[0];
  165. AsciiTable[keyCode].goofy.isDeadChar = true;
  166. // Need to clear the dead character from the keyboard layout:
  167. //ToAsciiEx( vKeyCode, dikCode, state, ascii, 0, layout );
  168. ToAscii( vKeyCode, dikCode, state, ascii, 0 );
  169. }
  170. state[VK_CONTROL] = 0;
  171. state[VK_MENU] = 0;
  172. }
  173. }
  174. }
  175. //------------------------------------------------------------------------------
  176. U16 Input::getKeyCode( U16 asciiCode )
  177. {
  178. U16 keyCode = 0;
  179. U16 i;
  180. // This is done three times so the lowerkey will always
  181. // be found first. Some foreign keyboards have duplicate
  182. // chars on some keys.
  183. for ( i = KEY_FIRST; i < NUM_KEYS && !keyCode; i++ )
  184. {
  185. if ( AsciiTable[i].lower.ascii == asciiCode )
  186. {
  187. keyCode = i;
  188. break;
  189. };
  190. }
  191. for ( i = KEY_FIRST; i < NUM_KEYS && !keyCode; i++ )
  192. {
  193. if ( AsciiTable[i].upper.ascii == asciiCode )
  194. {
  195. keyCode = i;
  196. break;
  197. };
  198. }
  199. for ( i = KEY_FIRST; i < NUM_KEYS && !keyCode; i++ )
  200. {
  201. if ( AsciiTable[i].goofy.ascii == asciiCode )
  202. {
  203. keyCode = i;
  204. break;
  205. };
  206. }
  207. return( keyCode );
  208. }
  209. //------------------------------------------------------------------------------
  210. U16 Input::getAscii( U16 keyCode, KEY_STATE keyState )
  211. {
  212. if ( keyCode >= NUM_KEYS )
  213. return 0;
  214. switch ( keyState )
  215. {
  216. case STATE_LOWER:
  217. return AsciiTable[keyCode].lower.ascii;
  218. case STATE_UPPER:
  219. return AsciiTable[keyCode].upper.ascii;
  220. case STATE_GOOFY:
  221. return AsciiTable[keyCode].goofy.ascii;
  222. default:
  223. return(0);
  224. }
  225. }
  226. //------------------------------------------------------------------------------
  227. void Input::destroy()
  228. {
  229. if ( smManager && smManager->isEnabled() )
  230. {
  231. smManager->disable();
  232. delete smManager;
  233. smManager = NULL;
  234. }
  235. }
  236. //------------------------------------------------------------------------------
  237. bool Input::enable()
  238. {
  239. if ( smManager && !smManager->isEnabled() )
  240. return( smManager->enable() );
  241. return( false );
  242. }
  243. //------------------------------------------------------------------------------
  244. void Input::disable()
  245. {
  246. if ( smManager && smManager->isEnabled() )
  247. smManager->disable();
  248. }
  249. //------------------------------------------------------------------------------
  250. void Input::activate()
  251. {
  252. #ifdef UNICODE
  253. winState.imeHandle = ImmGetContext( winState.appWindow );
  254. ImmReleaseContext( winState.appWindow, winState.imeHandle );
  255. #endif
  256. DInputDevice::resetModifierKeys();
  257. if ( !Con::getBoolVariable( "$enableDirectInput" ) )
  258. return;
  259. if ( smManager && smManager->isEnabled() && !smActive )
  260. {
  261. Con::printf( "Activating DirectInput..." );
  262. smActive = true;
  263. DInputManager* dInputManager = dynamic_cast<DInputManager*>( smManager );
  264. if ( dInputManager )
  265. {
  266. if ( dInputManager->isKeyboardEnabled() && smLastKeyboardActivated )
  267. dInputManager->activateKeyboard();
  268. if ( Video::isFullScreen() )
  269. {
  270. // DirectInput Mouse Hook-Up:
  271. if ( dInputManager->isMouseEnabled() && smLastMouseActivated )
  272. dInputManager->activateMouse();
  273. }
  274. else
  275. dInputManager->deactivateMouse();
  276. if ( dInputManager->isJoystickEnabled() && smLastJoystickActivated )
  277. dInputManager->activateJoystick();
  278. }
  279. }
  280. }
  281. //------------------------------------------------------------------------------
  282. void Input::deactivate()
  283. {
  284. if ( smManager && smManager->isEnabled() && smActive )
  285. {
  286. DInputManager* dInputManager = dynamic_cast<DInputManager*>( smManager );
  287. if ( dInputManager )
  288. {
  289. smLastKeyboardActivated = dInputManager->isKeyboardActive();
  290. smLastMouseActivated = dInputManager->isMouseActive();
  291. smLastJoystickActivated = dInputManager->isJoystickActive();
  292. dInputManager->deactivateKeyboard();
  293. dInputManager->deactivateMouse();
  294. dInputManager->deactivateJoystick();
  295. }
  296. smActive = false;
  297. Con::printf( "DirectInput deactivated." );
  298. }
  299. }
  300. //------------------------------------------------------------------------------
  301. void Input::reactivate()
  302. {
  303. // This is soo hacky...
  304. SetForegroundWindow( winState.appWindow );
  305. PostMessage( winState.appWindow, WM_ACTIVATE, WA_ACTIVE, NULL );
  306. }
  307. //------------------------------------------------------------------------------
  308. bool Input::isEnabled()
  309. {
  310. if ( smManager )
  311. return smManager->isEnabled();
  312. return false;
  313. }
  314. //------------------------------------------------------------------------------
  315. bool Input::isActive()
  316. {
  317. return smActive;
  318. }
  319. //------------------------------------------------------------------------------
  320. void Input::process()
  321. {
  322. if ( smManager && smManager->isEnabled() && smActive )
  323. smManager->process();
  324. }
  325. //------------------------------------------------------------------------------
  326. // Accesses the global input manager to see if its mouse is enabled
  327. bool Input::isMouseEnabled()
  328. {
  329. DInputManager* dInputManager = dynamic_cast<DInputManager*>( smManager );
  330. if ( !dInputManager || !dInputManager->isEnabled() )
  331. return( false );
  332. if (dInputManager->isMouseEnabled() && dInputManager->isMouseActive() )
  333. return( true );
  334. return false;
  335. }
  336. //------------------------------------------------------------------------------
  337. // Accesses the global input manager to see if its keyboard is enabled
  338. bool Input::isKeyboardEnabled()
  339. {
  340. DInputManager* dInputManager = dynamic_cast<DInputManager*>( smManager );
  341. if ( !dInputManager || !dInputManager->isEnabled() )
  342. return( false );
  343. if ( dInputManager->isKeyboardEnabled() && dInputManager->isKeyboardActive() )
  344. return( true );
  345. return false;
  346. }
  347. //------------------------------------------------------------------------------
  348. // Access the global input manager and enables its mouse
  349. void Input::enableMouse()
  350. {
  351. DInputManager::enableMouse();
  352. }
  353. //------------------------------------------------------------------------------
  354. // Access the global input manager and disables its mouse
  355. void Input::disableMouse()
  356. {
  357. DInputManager::disableMouse();
  358. }
  359. //------------------------------------------------------------------------------
  360. // Access the global input manager and enables its keyboard
  361. void Input::enableKeyboard()
  362. {
  363. DInputManager::enableKeyboard();
  364. }
  365. //------------------------------------------------------------------------------
  366. // Access the global input manager and enables its keyboard
  367. void Input::disableKeyboard()
  368. {
  369. DInputManager::disableKeyboard();
  370. }
  371. //------------------------------------------------------------------------------
  372. bool Input::activateKeyboard()
  373. {
  374. DInputManager* mgr = dynamic_cast<DInputManager*>( Input::getManager() );
  375. if ( mgr )
  376. return( mgr->activateKeyboard() );
  377. return( false );
  378. }
  379. //------------------------------------------------------------------------------
  380. void Input::deactivateKeyboard()
  381. {
  382. DInputManager* mgr = dynamic_cast<DInputManager*>( Input::getManager() );
  383. if ( mgr )
  384. mgr->deactivateKeyboard();
  385. }
  386. //------------------------------------------------------------------------------
  387. bool Input::enableJoystick()
  388. {
  389. return( DInputManager::enableJoystick() );
  390. }
  391. //------------------------------------------------------------------------------
  392. void Input::disableJoystick()
  393. {
  394. DInputManager::disableJoystick();
  395. }
  396. //------------------------------------------------------------------------------
  397. void Input::echoInputState()
  398. {
  399. DInputManager* mgr = dynamic_cast<DInputManager*>( Input::getManager() );
  400. if ( mgr && mgr->isEnabled() )
  401. {
  402. Con::printf( "DirectInput is enabled %s.", Input::isActive() ? "and active" : "but inactive" );
  403. Con::printf( "- Keyboard is %sabled and %sactive.",
  404. mgr->isKeyboardEnabled() ? "en" : "dis",
  405. mgr->isKeyboardActive() ? "" : "in" );
  406. Con::printf( "- Mouse is %sabled and %sactive.",
  407. mgr->isMouseEnabled() ? "en" : "dis",
  408. mgr->isMouseActive() ? "" : "in" );
  409. Con::printf( "- Joystick is %sabled and %sactive.",
  410. mgr->isJoystickEnabled() ? "en" : "dis",
  411. mgr->isJoystickActive() ? "" : "in" );
  412. Con::printf( "- Xinput is %sabled and %sactive.",
  413. mgr->isXInputEnabled() ? "en" : "dis",
  414. mgr->isXInputActive() ? "" : "in" );
  415. }
  416. else
  417. {
  418. Con::printf( "DirectInput is not enabled." );
  419. }
  420. }
  421. //------------------------------------------------------------------------------
  422. void Input::setCursorPos(S32 x, S32 y)
  423. {
  424. POINT pt;
  425. pt.x = x;
  426. pt.y = y;
  427. ClientToScreen(winState.appWindow, &pt);
  428. SetCursorPos(pt.x, pt.y);
  429. }
  430. //------------------------------------------------------------------------------
  431. // Set the cursor to draw (true) or not (false)
  432. void Input::setCursorState(bool on)
  433. {
  434. if (on)
  435. {
  436. while (ShowCursor(TRUE) < 0);
  437. }
  438. else
  439. {
  440. while (ShowCursor(FALSE) >= 0);
  441. }
  442. }
  443. //------------------------------------------------------------------------------
  444. static struct { U32 id; LPTSTR resourceID; } sgCursorShapeMap[]=
  445. {
  446. { CursorManager::curArrow, IDC_ARROW },
  447. { CursorManager::curWait, IDC_WAIT },
  448. { CursorManager::curPlus, IDC_CROSS },
  449. { CursorManager::curResizeVert, IDC_SIZEWE },
  450. { CursorManager::curResizeHorz, IDC_SIZENS },
  451. { CursorManager::curResizeAll, IDC_SIZEALL },
  452. { CursorManager::curIBeam, IDC_IBEAM },
  453. { CursorManager::curResizeNESW, IDC_SIZENESW },
  454. { CursorManager::curResizeNWSE, IDC_SIZENWSE },
  455. { 0, 0 },
  456. };
  457. void Input::setCursorShape(U32 cursorID)
  458. {
  459. LPTSTR resourceID = NULL;
  460. for(S32 i = 0;sgCursorShapeMap[i].resourceID != NULL;++i)
  461. {
  462. if(cursorID == sgCursorShapeMap[i].id)
  463. {
  464. resourceID = sgCursorShapeMap[i].resourceID;
  465. break;
  466. }
  467. }
  468. if(resourceID == NULL)
  469. return;
  470. HCURSOR cur = LoadCursor(NULL, resourceID);
  471. if(cur)
  472. SetCursor(cur);
  473. }
  474. //------------------------------------------------------------------------------
  475. // Functions to change the cursor shape using the Input class.
  476. void Input::pushCursor(S32 cursorID)
  477. {
  478. CursorManager* cm = getCursorManager();
  479. if(cm)
  480. cm->pushCursor(cursorID);
  481. }
  482. void Input::popCursor()
  483. {
  484. CursorManager* cm = getCursorManager();
  485. if(cm)
  486. cm->popCursor();
  487. }
  488. void Input::refreshCursor()
  489. {
  490. CursorManager* cm = getCursorManager();
  491. if(cm)
  492. cm->refreshCursor();
  493. }
  494. //------------------------------------------------------------------------------
  495. U32 Input::getDoubleClickTime()
  496. {
  497. return GetDoubleClickTime();
  498. }
  499. S32 Input::getDoubleClickWidth()
  500. {
  501. return GetSystemMetrics(SM_CXDOUBLECLK);
  502. }
  503. S32 Input::getDoubleClickHeight()
  504. {
  505. return GetSystemMetrics(SM_CYDOUBLECLK);
  506. }
  507. //------------------------------------------------------------------------------
  508. InputManager* Input::getManager()
  509. {
  510. return( smManager );
  511. }
  512. //------------------------------------------------------------------------------
  513. //------------------------------------------------------------------------------
  514. static U8 VcodeRemap[256] =
  515. {
  516. 0, // 0x00
  517. 0, // 0x01 VK_LBUTTON
  518. 0, // 0x02 VK_RBUTTON
  519. 0, // 0x03 VK_CANCEL
  520. 0, // 0x04 VK_MBUTTON
  521. 0, // 0x05
  522. 0, // 0x06
  523. 0, // 0x07
  524. KEY_BACKSPACE, // 0x08 VK_BACK
  525. KEY_TAB, // 0x09 VK_TAB
  526. 0, // 0x0A
  527. 0, // 0x0B
  528. 0, // 0x0C VK_CLEAR
  529. KEY_RETURN, // 0x0D VK_RETURN
  530. 0, // 0x0E
  531. 0, // 0x0F
  532. KEY_SHIFT, // 0x10 VK_SHIFT
  533. KEY_CONTROL, // 0x11 VK_CONTROL
  534. KEY_ALT, // 0x12 VK_MENU
  535. KEY_PAUSE, // 0x13 VK_PAUSE
  536. KEY_CAPSLOCK, // 0x14 VK_CAPITAL
  537. 0, // 0x15 VK_KANA, VK_HANGEUL, VK_HANGUL
  538. 0, // 0x16
  539. 0, // 0x17 VK_JUNJA
  540. 0, // 0x18 VK_FINAL
  541. 0, // 0x19 VK_HANJA, VK_KANJI
  542. 0, // 0x1A
  543. KEY_ESCAPE, // 0x1B VK_ESCAPE
  544. 0, // 0x1C VK_CONVERT
  545. 0, // 0x1D VK_NONCONVERT
  546. 0, // 0x1E VK_ACCEPT
  547. 0, // 0x1F VK_MODECHANGE
  548. KEY_SPACE, // 0x20 VK_SPACE
  549. KEY_PAGE_UP, // 0x21 VK_PRIOR
  550. KEY_PAGE_DOWN, // 0x22 VK_NEXT
  551. KEY_END, // 0x23 VK_END
  552. KEY_HOME, // 0x24 VK_HOME
  553. KEY_LEFT, // 0x25 VK_LEFT
  554. KEY_UP, // 0x26 VK_UP
  555. KEY_RIGHT, // 0x27 VK_RIGHT
  556. KEY_DOWN, // 0x28 VK_DOWN
  557. 0, // 0x29 VK_SELECT
  558. KEY_PRINT, // 0x2A VK_PRINT
  559. 0, // 0x2B VK_EXECUTE
  560. 0, // 0x2C VK_SNAPSHOT
  561. KEY_INSERT, // 0x2D VK_INSERT
  562. KEY_DELETE, // 0x2E VK_DELETE
  563. KEY_HELP, // 0x2F VK_HELP
  564. KEY_0, // 0x30 VK_0 VK_0 thru VK_9 are the same as ASCII '0' thru '9' (// 0x30 - // 0x39)
  565. KEY_1, // 0x31 VK_1
  566. KEY_2, // 0x32 VK_2
  567. KEY_3, // 0x33 VK_3
  568. KEY_4, // 0x34 VK_4
  569. KEY_5, // 0x35 VK_5
  570. KEY_6, // 0x36 VK_6
  571. KEY_7, // 0x37 VK_7
  572. KEY_8, // 0x38 VK_8
  573. KEY_9, // 0x39 VK_9
  574. 0, // 0x3A
  575. 0, // 0x3B
  576. 0, // 0x3C
  577. 0, // 0x3D
  578. 0, // 0x3E
  579. 0, // 0x3F
  580. 0, // 0x40
  581. KEY_A, // 0x41 VK_A VK_A thru VK_Z are the same as ASCII 'A' thru 'Z' (// 0x41 - // 0x5A)
  582. KEY_B, // 0x42 VK_B
  583. KEY_C, // 0x43 VK_C
  584. KEY_D, // 0x44 VK_D
  585. KEY_E, // 0x45 VK_E
  586. KEY_F, // 0x46 VK_F
  587. KEY_G, // 0x47 VK_G
  588. KEY_H, // 0x48 VK_H
  589. KEY_I, // 0x49 VK_I
  590. KEY_J, // 0x4A VK_J
  591. KEY_K, // 0x4B VK_K
  592. KEY_L, // 0x4C VK_L
  593. KEY_M, // 0x4D VK_M
  594. KEY_N, // 0x4E VK_N
  595. KEY_O, // 0x4F VK_O
  596. KEY_P, // 0x50 VK_P
  597. KEY_Q, // 0x51 VK_Q
  598. KEY_R, // 0x52 VK_R
  599. KEY_S, // 0x53 VK_S
  600. KEY_T, // 0x54 VK_T
  601. KEY_U, // 0x55 VK_U
  602. KEY_V, // 0x56 VK_V
  603. KEY_W, // 0x57 VK_W
  604. KEY_X, // 0x58 VK_X
  605. KEY_Y, // 0x59 VK_Y
  606. KEY_Z, // 0x5A VK_Z
  607. KEY_WIN_LWINDOW, // 0x5B VK_LWIN
  608. KEY_WIN_RWINDOW, // 0x5C VK_RWIN
  609. KEY_WIN_APPS, // 0x5D VK_APPS
  610. 0, // 0x5E
  611. 0, // 0x5F
  612. KEY_NUMPAD0, // 0x60 VK_NUMPAD0
  613. KEY_NUMPAD1, // 0x61 VK_NUMPAD1
  614. KEY_NUMPAD2, // 0x62 VK_NUMPAD2
  615. KEY_NUMPAD3, // 0x63 VK_NUMPAD3
  616. KEY_NUMPAD4, // 0x64 VK_NUMPAD4
  617. KEY_NUMPAD5, // 0x65 VK_NUMPAD5
  618. KEY_NUMPAD6, // 0x66 VK_NUMPAD6
  619. KEY_NUMPAD7, // 0x67 VK_NUMPAD7
  620. KEY_NUMPAD8, // 0x68 VK_NUMPAD8
  621. KEY_NUMPAD9, // 0x69 VK_NUMPAD9
  622. KEY_MULTIPLY, // 0x6A VK_MULTIPLY
  623. KEY_ADD, // 0x6B VK_ADD
  624. KEY_SEPARATOR, // 0x6C VK_SEPARATOR
  625. KEY_SUBTRACT, // 0x6D VK_SUBTRACT
  626. KEY_DECIMAL, // 0x6E VK_DECIMAL
  627. KEY_DIVIDE, // 0x6F VK_DIVIDE
  628. KEY_F1, // 0x70 VK_F1
  629. KEY_F2, // 0x71 VK_F2
  630. KEY_F3, // 0x72 VK_F3
  631. KEY_F4, // 0x73 VK_F4
  632. KEY_F5, // 0x74 VK_F5
  633. KEY_F6, // 0x75 VK_F6
  634. KEY_F7, // 0x76 VK_F7
  635. KEY_F8, // 0x77 VK_F8
  636. KEY_F9, // 0x78 VK_F9
  637. KEY_F10, // 0x79 VK_F10
  638. KEY_F11, // 0x7A VK_F11
  639. KEY_F12, // 0x7B VK_F12
  640. KEY_F13, // 0x7C VK_F13
  641. KEY_F14, // 0x7D VK_F14
  642. KEY_F15, // 0x7E VK_F15
  643. KEY_F16, // 0x7F VK_F16
  644. KEY_F17, // 0x80 VK_F17
  645. KEY_F18, // 0x81 VK_F18
  646. KEY_F19, // 0x82 VK_F19
  647. KEY_F20, // 0x83 VK_F20
  648. KEY_F21, // 0x84 VK_F21
  649. KEY_F22, // 0x85 VK_F22
  650. KEY_F23, // 0x86 VK_F23
  651. KEY_F24, // 0x87 VK_F24
  652. 0, // 0x88
  653. 0, // 0x89
  654. 0, // 0x8A
  655. 0, // 0x8B
  656. 0, // 0x8C
  657. 0, // 0x8D
  658. 0, // 0x8E
  659. 0, // 0x8F
  660. KEY_NUMLOCK, // 0x90 VK_NUMLOCK
  661. KEY_SCROLLLOCK, // 0x91 VK_OEM_SCROLL
  662. 0, // 0x92
  663. 0, // 0x93
  664. 0, // 0x94
  665. 0, // 0x95
  666. 0, // 0x96
  667. 0, // 0x97
  668. 0, // 0x98
  669. 0, // 0x99
  670. 0, // 0x9A
  671. 0, // 0x9B
  672. 0, // 0x9C
  673. 0, // 0x9D
  674. 0, // 0x9E
  675. 0, // 0x9F
  676. KEY_LSHIFT, // 0xA0 VK_LSHIFT
  677. KEY_RSHIFT, // 0xA1 VK_RSHIFT
  678. KEY_LCONTROL, // 0xA2 VK_LCONTROL
  679. KEY_RCONTROL, // 0xA3 VK_RCONTROL
  680. KEY_LALT, // 0xA4 VK_LMENU
  681. KEY_RALT, // 0xA5 VK_RMENU
  682. 0, // 0xA6
  683. 0, // 0xA7
  684. 0, // 0xA8
  685. 0, // 0xA9
  686. 0, // 0xAA
  687. 0, // 0xAB
  688. 0, // 0xAC
  689. 0, // 0xAD
  690. 0, // 0xAE
  691. 0, // 0xAF
  692. 0, // 0xB0
  693. 0, // 0xB1
  694. 0, // 0xB2
  695. 0, // 0xB3
  696. 0, // 0xB4
  697. 0, // 0xB5
  698. 0, // 0xB6
  699. 0, // 0xB7
  700. 0, // 0xB8
  701. 0, // 0xB9
  702. KEY_SEMICOLON, // 0xBA VK_OEM_1
  703. KEY_EQUALS, // 0xBB VK_OEM_PLUS
  704. KEY_COMMA, // 0xBC VK_OEM_COMMA
  705. KEY_MINUS, // 0xBD VK_OEM_MINUS
  706. KEY_PERIOD, // 0xBE VK_OEM_PERIOD
  707. KEY_SLASH, // 0xBF VK_OEM_2
  708. KEY_TILDE, // 0xC0 VK_OEM_3
  709. 0, // 0xC1
  710. 0, // 0xC2
  711. 0, // 0xC3
  712. 0, // 0xC4
  713. 0, // 0xC5
  714. 0, // 0xC6
  715. 0, // 0xC7
  716. 0, // 0xC8
  717. 0, // 0xC9
  718. 0, // 0xCA
  719. 0, // 0xCB
  720. 0, // 0xCC
  721. 0, // 0xCD
  722. 0, // 0xCE
  723. 0, // 0xCF
  724. 0, // 0xD0
  725. 0, // 0xD1
  726. 0, // 0xD2
  727. 0, // 0xD3
  728. 0, // 0xD4
  729. 0, // 0xD5
  730. 0, // 0xD6
  731. 0, // 0xD7
  732. 0, // 0xD8
  733. 0, // 0xD9
  734. 0, // 0xDA
  735. KEY_LBRACKET, // 0xDB VK_OEM_4
  736. KEY_BACKSLASH, // 0xDC VK_OEM_5
  737. KEY_RBRACKET, // 0xDD VK_OEM_6
  738. KEY_APOSTROPHE, // 0xDE VK_OEM_7
  739. 0, // 0xDF VK_OEM_8
  740. 0, // 0xE0
  741. 0, // 0xE1 VK_OEM_AX AX key on Japanese AX keyboard
  742. KEY_OEM_102, // 0xE2 VK_OEM_102
  743. 0, // 0xE3
  744. 0, // 0xE4
  745. 0, // 0xE5 VK_PROCESSKEY
  746. 0, // 0xE6
  747. 0, // 0xE7
  748. 0, // 0xE8
  749. 0, // 0xE9
  750. 0, // 0xEA
  751. 0, // 0xEB
  752. 0, // 0xEC
  753. 0, // 0xED
  754. 0, // 0xEE
  755. 0, // 0xEF
  756. 0, // 0xF0
  757. 0, // 0xF1
  758. 0, // 0xF2
  759. 0, // 0xF3
  760. 0, // 0xF4
  761. 0, // 0xF5
  762. 0, // 0xF6 VK_ATTN
  763. 0, // 0xF7 VK_CRSEL
  764. 0, // 0xF8 VK_EXSEL
  765. 0, // 0xF9 VK_EREOF
  766. 0, // 0xFA VK_PLAY
  767. 0, // 0xFB VK_ZOOM
  768. 0, // 0xFC VK_NONAME
  769. 0, // 0xFD VK_PA1
  770. 0, // 0xFE VK_OEM_CLEAR
  771. 0 // 0xFF
  772. };
  773. //------------------------------------------------------------------------------
  774. //
  775. // This function translates a virtual key code to our corresponding internal
  776. // key code using the preceding table.
  777. //
  778. //------------------------------------------------------------------------------
  779. U8 TranslateOSKeyCode(U8 vcode)
  780. {
  781. return VcodeRemap[vcode];
  782. }
  783. //-----------------------------------------------------------------------------
  784. // Clipboard functions
  785. const char* Platform::getClipboard()
  786. {
  787. HGLOBAL hGlobal;
  788. LPVOID pGlobal;
  789. //make sure we can access the clipboard
  790. if (!IsClipboardFormatAvailable(CF_TEXT))
  791. return "";
  792. if (!OpenClipboard(NULL))
  793. return "";
  794. hGlobal = GetClipboardData(CF_TEXT);
  795. pGlobal = GlobalLock(hGlobal);
  796. S32 cbLength = strlen((char *)pGlobal);
  797. char *returnBuf = Con::getReturnBuffer(cbLength + 1);
  798. strcpy(returnBuf, (char *)pGlobal);
  799. returnBuf[cbLength] = '\0';
  800. GlobalUnlock(hGlobal);
  801. CloseClipboard();
  802. //note - this function never returns NULL
  803. return returnBuf;
  804. }
  805. //-----------------------------------------------------------------------------
  806. bool Platform::setClipboard(const char *text)
  807. {
  808. if (!text)
  809. return false;
  810. //make sure we can access the clipboard
  811. if (!OpenClipboard(NULL))
  812. return false;
  813. S32 cbLength = strlen(text);
  814. HGLOBAL hGlobal;
  815. LPVOID pGlobal;
  816. hGlobal = GlobalAlloc(GHND, cbLength + 1);
  817. pGlobal = GlobalLock (hGlobal);
  818. strcpy((char *)pGlobal, text);
  819. GlobalUnlock(hGlobal);
  820. EmptyClipboard();
  821. SetClipboardData(CF_TEXT, hGlobal);
  822. CloseClipboard();
  823. return true;
  824. }