keyboard.cpp 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773
  1. /*
  2. ** Command & Conquer Renegade(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /***********************************************************************************************
  19. *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
  20. ***********************************************************************************************
  21. * *
  22. * Project Name : Command & Conquer *
  23. * *
  24. * $Archive:: /G/wwlib/KEYBOARD.CPP $*
  25. * *
  26. * $Author:: Eric_c $*
  27. * *
  28. * $Modtime:: 4/15/99 10:15a $*
  29. * *
  30. * $Revision:: 2 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * WWKeyboardClass::Buff_Get -- Lowlevel function to get a key from key buffer *
  35. * WWKeyboardClass::Check -- Checks to see if a key is in the buffer *
  36. * WWKeyboardClass::Clear -- Clears the keyboard buffer. *
  37. * WWKeyboardClass::Down -- Checks to see if the specified key is being held down. *
  38. * WWKeyboardClass::Fetch_Element -- Extract the next element in the keyboard buffer. *
  39. * WWKeyboardClass::Fill_Buffer_From_Syste -- Extract and process any queued windows messages*
  40. * WWKeyboardClass::Get -- Logic to get a metakey from the buffer *
  41. * WWKeyboardClass::Get_Mouse_X -- Returns the mouses current x position in pixels *
  42. * WWKeyboardClass::Get_Mouse_XY -- Returns the mouses x,y position via reference vars *
  43. * WWKeyboardClass::Get_Mouse_Y -- returns the mouses current y position in pixels *
  44. * WWKeyboardClass::Is_Buffer_Empty -- Checks to see if the keyboard buffer is empty. *
  45. * WWKeyboardClass::Is_Buffer_Full -- Determines if the keyboard buffer is full. *
  46. * WWKeyboardClass::Is_Mouse_Key -- Checks to see if specified key refers to the mouse. *
  47. * WWKeyboardClass::Message_Handler -- Process a windows message as it relates to the keyboar*
  48. * WWKeyboardClass::Peek_Element -- Fetches the next element in the keyboard buffer. *
  49. * WWKeyboardClass::Put -- Logic to insert a key into the keybuffer] *
  50. * WWKeyboardClass::Put_Element -- Put a keyboard data element into the buffer. *
  51. * WWKeyboardClass::Put_Key_Message -- Translates and inserts wParam into Keyboard Buffer *
  52. * WWKeyboardClass::To_ASCII -- Convert the key value into an ASCII representation. *
  53. * WWKeyboardClass::Available_Buffer_Room -- Fetch the quantity of free elements in the keybo*
  54. * WWKeyboardClass::Put_Mouse_Message -- Stores a mouse type message into the keyboard buffer*
  55. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  56. #include "always.h"
  57. #include "_xmouse.h"
  58. #include "keyboard.h"
  59. //#include "mono.h"
  60. #include "msgloop.h"
  61. #define ARRAY_SIZE(x) int(sizeof(x)/sizeof(x[0]))
  62. void Stop_Execution (void)
  63. {
  64. // __asm nop // Is this line needed?
  65. }
  66. /***********************************************************************************************
  67. * WWKeyboardClass::WWKeyBoardClass -- Construction for Westwood Keyboard Class *
  68. * *
  69. * INPUT: none *
  70. * *
  71. * OUTPUT: none *
  72. * *
  73. * HISTORY: *
  74. * 10/16/1995 PWG : Created. *
  75. *=============================================================================================*/
  76. WWKeyboardClass::WWKeyboardClass(void) :
  77. MouseQX(0),
  78. MouseQY(0),
  79. Head(0),
  80. Tail(0)
  81. {
  82. memset(KeyState, '\0', sizeof(KeyState));
  83. }
  84. /***********************************************************************************************
  85. * WWKeyboardClass::Buff_Get -- Lowlevel function to get a key from key buffer *
  86. * *
  87. * INPUT: none *
  88. * *
  89. * OUTPUT: int - the key value that was pulled from buffer (includes bits) * *
  90. * *
  91. * WARNINGS: If the key was a mouse event MouseQX and MouseQY will be updated *
  92. * *
  93. * HISTORY: *
  94. * 10/17/1995 PWG : Created. *
  95. *=============================================================================================*/
  96. unsigned short WWKeyboardClass::Buff_Get(void)
  97. {
  98. while (!Check()) {} // wait for key in buffer
  99. unsigned short temp = Fetch_Element();
  100. if (Is_Mouse_Key(temp)) {
  101. MouseQX = Fetch_Element();
  102. MouseQY = Fetch_Element();
  103. }
  104. return(temp);
  105. }
  106. /***********************************************************************************************
  107. * WWKeyboardClass::Is_Mouse_Key -- Checks to see if specified key refers to the mouse. *
  108. * *
  109. * This checks the specified key code to see if it refers to the mouse buttons. *
  110. * *
  111. * INPUT: key -- The key to check. *
  112. * *
  113. * OUTPUT: bool; Is the key a mouse button key? *
  114. * *
  115. * WARNINGS: none *
  116. * *
  117. * HISTORY: *
  118. * 09/30/1996 JLB : Created. *
  119. *=============================================================================================*/
  120. bool WWKeyboardClass::Is_Mouse_Key(unsigned short key)
  121. {
  122. key &= 0xFF;
  123. return (key == VK_LBUTTON || key == VK_MBUTTON || key == VK_RBUTTON);
  124. }
  125. /***********************************************************************************************
  126. * WWKeyboardClass::Check -- Checks to see if a key is in the buffer *
  127. * *
  128. * INPUT: *
  129. * *
  130. * OUTPUT: *
  131. * *
  132. * WARNINGS: *
  133. * *
  134. * HISTORY: *
  135. * 10/16/1995 PWG : Created. *
  136. * 09/24/1996 JLB : Converted to new style keyboard system. *
  137. *=============================================================================================*/
  138. unsigned short WWKeyboardClass::Check(void) const
  139. {
  140. ((WWKeyboardClass *)this)->Fill_Buffer_From_System();
  141. if (Is_Buffer_Empty()) return(false);
  142. return(Peek_Element());
  143. }
  144. /***********************************************************************************************
  145. * WWKeyboardClass::Get -- Logic to get a metakey from the buffer *
  146. * *
  147. * INPUT: none *
  148. * *
  149. * OUTPUT: int - the meta key taken from the buffer. *
  150. * *
  151. * WARNINGS: This routine will not return until a keypress is received *
  152. * *
  153. * HISTORY: *
  154. * 10/16/1995 PWG : Created. *
  155. *=============================================================================================*/
  156. unsigned short WWKeyboardClass::Get(void)
  157. {
  158. while (!Check()) {} // wait for key in buffer
  159. return (Buff_Get());
  160. }
  161. /***********************************************************************************************
  162. * WWKeyboardClass::Put -- Logic to insert a key into the keybuffer] *
  163. * *
  164. * INPUT: int - the key to insert into the buffer *
  165. * *
  166. * OUTPUT: bool - true if key is sucessfuly inserted. *
  167. * *
  168. * WARNINGS: none *
  169. * *
  170. * HISTORY: *
  171. * 10/16/1995 PWG : Created. *
  172. *=============================================================================================*/
  173. bool WWKeyboardClass::Put(unsigned short key)
  174. {
  175. if (!Is_Buffer_Full()) {
  176. Put_Element(key);
  177. return(true);
  178. }
  179. return(false);
  180. }
  181. /***********************************************************************************************
  182. * WWKeyboardClass::Put_Key_Message -- Translates and inserts wParam into Keyboard Buffer *
  183. * *
  184. * INPUT: *
  185. * *
  186. * OUTPUT: *
  187. * *
  188. * WARNINGS: *
  189. * *
  190. * HISTORY: *
  191. * 10/16/1995 PWG : Created. *
  192. *=============================================================================================*/
  193. bool WWKeyboardClass::Put_Key_Message(unsigned short vk_key, bool release)
  194. {
  195. /*
  196. ** Get the status of all of the different keyboard modifiers. Note, only pay attention
  197. ** to numlock and caps lock if we are dealing with a key that is affected by them. Note
  198. ** that we do not want to set the shift, ctrl and alt bits for Mouse keypresses as this
  199. ** would be incompatible with the dos version.
  200. */
  201. if (!Is_Mouse_Key(vk_key)) {
  202. if (((GetKeyState(VK_SHIFT) & 0x8000) != 0) ||
  203. ((GetKeyState(VK_CAPITAL) & 0x0008) != 0) ||
  204. ((GetKeyState(VK_NUMLOCK) & 0x0008) != 0)) {
  205. vk_key |= WWKEY_SHIFT_BIT;
  206. }
  207. if ((GetKeyState(VK_CONTROL) & 0x8000) != 0) {
  208. vk_key |= WWKEY_CTRL_BIT;
  209. }
  210. if ((GetKeyState(VK_MENU) & 0x8000) != 0) {
  211. vk_key |= WWKEY_ALT_BIT;
  212. }
  213. }
  214. if (release) {
  215. vk_key |= WWKEY_RLS_BIT;
  216. }
  217. /*
  218. ** Finally use the put command to enter the key into the keyboard
  219. ** system.
  220. */
  221. return(Put(vk_key));
  222. }
  223. /***********************************************************************************************
  224. * WWKeyboardClass::Put_Mouse_Message -- Stores a mouse type message into the keyboard buffer. *
  225. * *
  226. * This routine will store the mouse type event into the keyboard buffer. It also checks *
  227. * to ensure that there is enough room in the buffer so that partial mouse events won't *
  228. * be recorded. *
  229. * *
  230. * INPUT: vk_key -- The mouse key message itself. *
  231. * *
  232. * x,y -- The mouse coordinates at the time of the event. *
  233. * *
  234. * release -- Is this a mouse button release? *
  235. * *
  236. * OUTPUT: bool; Was the event stored sucessfully into the keyboard buffer? *
  237. * *
  238. * WARNINGS: none *
  239. * *
  240. * HISTORY: *
  241. * 11/02/1996 JLB : Created. *
  242. *=============================================================================================*/
  243. bool WWKeyboardClass::Put_Mouse_Message(unsigned short vk_key, int x, int y, bool release)
  244. {
  245. if (Available_Buffer_Room() >= 3 && Is_Mouse_Key(vk_key)) {
  246. Put_Key_Message(vk_key, release);
  247. Put((unsigned short)x);
  248. Put((unsigned short)y);
  249. return(true);
  250. }
  251. return(false);
  252. }
  253. /***********************************************************************************************
  254. * WWKeyboardClass::To_ASCII -- Convert the key value into an ASCII representation. *
  255. * *
  256. * This routine will convert the key code specified into an ASCII value. This takes into *
  257. * consideration the language and keyboard mapping of the host Windows system. *
  258. * *
  259. * INPUT: key -- The key code to convert into ASCII. *
  260. * *
  261. * OUTPUT: Returns with the key converted into ASCII. If the key has no ASCII equivalent, *
  262. * then '\0' is returned. *
  263. * *
  264. * WARNINGS: none *
  265. * *
  266. * HISTORY: *
  267. * 09/30/1996 JLB : Created. *
  268. *=============================================================================================*/
  269. char WWKeyboardClass::To_ASCII(unsigned short key)
  270. {
  271. /*
  272. ** Released keys never translate into an ASCII value.
  273. */
  274. if (key & WWKEY_RLS_BIT) {
  275. return('\0');
  276. }
  277. /*
  278. ** Set the KeyState buffer to reflect the shift bits stored in the key value.
  279. */
  280. if (key & WWKEY_SHIFT_BIT) {
  281. KeyState[VK_SHIFT] = 0x80;
  282. }
  283. if (key & WWKEY_CTRL_BIT) {
  284. KeyState[VK_CONTROL] = 0x80;
  285. }
  286. if (key & WWKEY_ALT_BIT) {
  287. KeyState[VK_MENU] = 0x80;
  288. }
  289. /*
  290. ** Ask windows to translate the key into an ASCII equivalent.
  291. */
  292. char buffer[10];
  293. int result;
  294. // int result = 1;
  295. int scancode;
  296. // int scancode = 0;
  297. scancode = MapVirtualKey(key & 0xFF, 0);
  298. result = ToAscii((UINT)(key & 0xFF), (UINT)scancode, (PBYTE)KeyState, (LPWORD)buffer, (UINT)0);
  299. /*
  300. ** Restore the KeyState buffer back to pristine condition.
  301. */
  302. if (key & WWKEY_SHIFT_BIT) {
  303. KeyState[VK_SHIFT] = 0;
  304. }
  305. if (key & WWKEY_CTRL_BIT) {
  306. KeyState[VK_CONTROL] = 0;
  307. }
  308. if (key & WWKEY_ALT_BIT) {
  309. KeyState[VK_MENU] = 0;
  310. }
  311. /*
  312. ** If Windows could not perform the translation as expected, then
  313. ** return with a null ASCII value.
  314. */
  315. if (result != 1) {
  316. return('\0');
  317. }
  318. return(buffer[0]);
  319. }
  320. /***********************************************************************************************
  321. * WWKeyboardClass::Down -- Checks to see if the specified key is being held down. *
  322. * *
  323. * This routine will examine the key specified to see if it is currently being held down. *
  324. * *
  325. * INPUT: key -- The key to check. *
  326. * *
  327. * OUTPUT: bool; Is the specified key currently being held down? *
  328. * *
  329. * WARNINGS: none *
  330. * *
  331. * HISTORY: *
  332. * 09/30/1996 JLB : Created. *
  333. *=============================================================================================*/
  334. bool WWKeyboardClass::Down(unsigned short key)
  335. {
  336. return(GetAsyncKeyState(key & 0xFF) != 0);
  337. }
  338. //extern "C" {
  339. // void __cdecl Stop_Execution (void);
  340. //}
  341. /***********************************************************************************************
  342. * WWKeyboardClass::Fetch_Element -- Extract the next element in the keyboard buffer. *
  343. * *
  344. * This routine will extract the next pending element in the keyboard queue. If there is *
  345. * no element available, then NULL is returned. *
  346. * *
  347. * INPUT: none *
  348. * *
  349. * OUTPUT: Returns with the element extracted from the queue. An empty queue is signified *
  350. * by a 0 return value. *
  351. * *
  352. * WARNINGS: *
  353. * *
  354. * HISTORY: *
  355. * 09/30/1996 JLB : Created. *
  356. *=============================================================================================*/
  357. unsigned short WWKeyboardClass::Fetch_Element(void)
  358. {
  359. unsigned short val = 0;
  360. if (Head != Tail) {
  361. val = Buffer[Head];
  362. Head = (Head + 1) % ARRAY_SIZE(Buffer);
  363. }
  364. return(val);
  365. }
  366. /***********************************************************************************************
  367. * WWKeyboardClass::Peek_Element -- Fetches the next element in the keyboard buffer. *
  368. * *
  369. * This routine will examine and return with the next element in the keyboard buffer but *
  370. * it will not alter or remove that element. Use this routine to see what is pending in *
  371. * the keyboard queue. *
  372. * *
  373. * INPUT: none *
  374. * *
  375. * OUTPUT: Returns with the next element in the keyboard queue. If the keyboard buffer is *
  376. * empty, then 0 is returned. *
  377. * *
  378. * WARNINGS: none *
  379. * *
  380. * HISTORY: *
  381. * 09/30/1996 JLB : Created. *
  382. *=============================================================================================*/
  383. unsigned short WWKeyboardClass::Peek_Element(void) const
  384. {
  385. if (!Is_Buffer_Empty()) {
  386. return(Buffer[Head]);
  387. }
  388. return(0);
  389. }
  390. /***********************************************************************************************
  391. * WWKeyboardClass::Put_Element -- Put a keyboard data element into the buffer. *
  392. * *
  393. * This will put one keyboard data element into the keyboard buffer. Typically, this data *
  394. * is a key code, but it might be mouse coordinates. *
  395. * *
  396. * INPUT: val -- The data element to add to the keyboard buffer. *
  397. * *
  398. * OUTPUT: bool; Was the keyboard element added successfully? A failure would indicate that *
  399. * the keyboard buffer is full. *
  400. * *
  401. * WARNINGS: none *
  402. * *
  403. * HISTORY: *
  404. * 09/30/1996 JLB : Created. *
  405. *=============================================================================================*/
  406. bool WWKeyboardClass::Put_Element(unsigned short val)
  407. {
  408. if (!Is_Buffer_Full()) {
  409. int temp = (Tail+1) % ARRAY_SIZE(Buffer);
  410. Buffer[Tail] = val;
  411. Tail = temp;
  412. return(true);
  413. }
  414. return(false);
  415. }
  416. /***********************************************************************************************
  417. * WWKeyboardClass::Is_Buffer_Full -- Determines if the keyboard buffer is full. *
  418. * *
  419. * This routine will examine the keyboard buffer to determine if it is completely *
  420. * full of queued keyboard events. *
  421. * *
  422. * INPUT: none *
  423. * *
  424. * OUTPUT: bool; Is the keyboard buffer completely full? *
  425. * *
  426. * WARNINGS: none *
  427. * *
  428. * HISTORY: *
  429. * 09/30/1996 JLB : Created. *
  430. *=============================================================================================*/
  431. bool WWKeyboardClass::Is_Buffer_Full(void) const
  432. {
  433. if ((Tail + 1) % ARRAY_SIZE(Buffer) == Head) {
  434. return(true);
  435. }
  436. return(false);
  437. }
  438. /***********************************************************************************************
  439. * WWKeyboardClass::Is_Buffer_Empty -- Checks to see if the keyboard buffer is empty. *
  440. * *
  441. * This routine will examine the keyboard buffer to see if it contains no events at all. *
  442. * *
  443. * INPUT: none *
  444. * *
  445. * OUTPUT: bool; Is the keyboard buffer currently without any pending events queued? *
  446. * *
  447. * WARNINGS: none *
  448. * *
  449. * HISTORY: *
  450. * 09/30/1996 JLB : Created. *
  451. *=============================================================================================*/
  452. bool WWKeyboardClass::Is_Buffer_Empty(void) const
  453. {
  454. if (Head == Tail) {
  455. return(true);
  456. }
  457. return(false);
  458. }
  459. /***********************************************************************************************
  460. * WWKeyboardClass::Fill_Buffer_From_Syste -- Extract and process any queued windows messages. *
  461. * *
  462. * This routine will extract and process any windows messages in the windows message *
  463. * queue. It is presumed that the normal message handler will call the keyboard *
  464. * message processing function. *
  465. * *
  466. * INPUT: none *
  467. * *
  468. * OUTPUT: none *
  469. * *
  470. * WARNINGS: none *
  471. * *
  472. * HISTORY: *
  473. * 09/30/1996 JLB : Created. *
  474. *=============================================================================================*/
  475. void WWKeyboardClass::Fill_Buffer_From_System(void)
  476. {
  477. if (!Is_Buffer_Full()) {
  478. Windows_Message_Handler();
  479. // MSG msg;
  480. // while (PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE)) {
  481. // if (!GetMessage( &msg, NULL, 0, 0 )) {
  482. // return;
  483. // }
  484. // TranslateMessage(&msg);
  485. // DispatchMessage(&msg);
  486. // }
  487. }
  488. }
  489. /***********************************************************************************************
  490. * WWKeyboardClass::Clear -- Clears the keyboard buffer. *
  491. * *
  492. * This routine will clear the keyboard buffer of all pending keyboard events. *
  493. * *
  494. * INPUT: none *
  495. * *
  496. * OUTPUT: none *
  497. * *
  498. * WARNINGS: none *
  499. * *
  500. * HISTORY: *
  501. * 09/30/1996 JLB : Created. *
  502. *=============================================================================================*/
  503. void WWKeyboardClass::Clear(void)
  504. {
  505. /*
  506. ** Extract any windows pending keyboard message events and then clear out the keyboard
  507. ** buffer.
  508. */
  509. Fill_Buffer_From_System();
  510. Head = Tail;
  511. /*
  512. ** Perform a second clear to handle the rare case of the keyboard buffer being full and there
  513. ** still remains keyboard related events in the windows message queue.
  514. */
  515. Fill_Buffer_From_System();
  516. Head = Tail;
  517. }
  518. /***********************************************************************************************
  519. * WWKeyboardClass::Message_Handler -- Process a windows message as it relates to the keyboard *
  520. * *
  521. * This routine will examine the Windows message specified. If the message relates to an *
  522. * event that the keyboard input system needs to process, then it will be processed *
  523. * accordingly. *
  524. * *
  525. * INPUT: window -- Handle to the window receiving the message. *
  526. * *
  527. * message -- The message number of this event. *
  528. * *
  529. * wParam -- The windows specific word parameter (meaning depends on message). *
  530. * *
  531. * lParam -- The windows specific long word parameter (meaning is message dependant)*
  532. * *
  533. * OUTPUT: bool; Was this keyboard message recognized and processed? A 'false' return value *
  534. * means that the message should be processed normally. *
  535. * *
  536. * WARNINGS: none *
  537. * *
  538. * HISTORY: *
  539. * 09/30/1996 JLB : Created. *
  540. *=============================================================================================*/
  541. bool WWKeyboardClass::Message_Handler(HWND window, UINT message, UINT wParam, LONG lParam)
  542. {
  543. bool processed = false;
  544. POINT point;
  545. point.x = LOWORD(lParam);
  546. point.y = HIWORD(lParam);
  547. ClientToScreen(window, &point);
  548. int x = point.x;
  549. int y = point.y;
  550. // Special conversion to game coordinates is needed here.
  551. if (MouseCursor != NULL) MouseCursor->Convert_Coordinate(x, y);
  552. /*
  553. ** Examine the message to see if it is one that should be processed. Only keyboard and
  554. ** pertinant mouse messages are processed.
  555. */
  556. switch (message) {
  557. /*
  558. ** System key has been pressed. This is the normal keyboard event message.
  559. */
  560. case WM_SYSKEYDOWN:
  561. case WM_KEYDOWN:
  562. if (wParam == VK_SCROLL) {
  563. Stop_Execution();
  564. } else {
  565. Put_Key_Message((unsigned short)wParam);
  566. }
  567. processed = true;
  568. break;
  569. /*
  570. ** The key has been released. This is the normal key release message.
  571. */
  572. case WM_SYSKEYUP:
  573. case WM_KEYUP:
  574. Put_Key_Message((unsigned short)wParam, true);
  575. processed = true;
  576. break;
  577. /*
  578. ** Press of the left mouse button.
  579. */
  580. case WM_LBUTTONDOWN:
  581. Put_Mouse_Message(VK_LBUTTON, x, y);
  582. processed = true;
  583. break;
  584. /*
  585. ** Release of the left mouse button.
  586. */
  587. case WM_LBUTTONUP:
  588. Put_Mouse_Message(VK_LBUTTON, x, y, true);
  589. processed = true;
  590. break;
  591. /*
  592. ** Double click of the left mouse button. Fake this into being
  593. ** just a rapid click of the left button twice.
  594. */
  595. case WM_LBUTTONDBLCLK:
  596. Put_Mouse_Message(VK_LBUTTON, x, y);
  597. Put_Mouse_Message(VK_LBUTTON, x, y, true);
  598. Put_Mouse_Message(VK_LBUTTON, x, y);
  599. Put_Mouse_Message(VK_LBUTTON, x, y, true);
  600. processed = true;
  601. break;
  602. /*
  603. ** Press of the middle mouse button.
  604. */
  605. case WM_MBUTTONDOWN:
  606. Put_Mouse_Message(VK_MBUTTON, x, y);
  607. processed = true;
  608. break;
  609. /*
  610. ** Release of the middle mouse button.
  611. */
  612. case WM_MBUTTONUP:
  613. Put_Mouse_Message(VK_MBUTTON, x, y, true);
  614. processed = true;
  615. break;
  616. /*
  617. ** Middle button double click gets translated into two
  618. ** regular middle button clicks.
  619. */
  620. case WM_MBUTTONDBLCLK:
  621. Put_Mouse_Message(VK_MBUTTON, x, y);
  622. Put_Mouse_Message(VK_MBUTTON, x, y, true);
  623. Put_Mouse_Message(VK_MBUTTON, x, y);
  624. Put_Mouse_Message(VK_MBUTTON, x, y, true);
  625. processed = true;
  626. break;
  627. /*
  628. ** Right mouse button press.
  629. */
  630. case WM_RBUTTONDOWN:
  631. Put_Mouse_Message(VK_RBUTTON, x, y);
  632. processed = true;
  633. break;
  634. /*
  635. ** Right mouse button release.
  636. */
  637. case WM_RBUTTONUP:
  638. Put_Mouse_Message(VK_RBUTTON, x, y, true);
  639. processed = true;
  640. break;
  641. /*
  642. ** Translate a double click of the right button
  643. ** into being just two regular right button clicks.
  644. */
  645. case WM_RBUTTONDBLCLK:
  646. Put_Mouse_Message(VK_RBUTTON, x, y);
  647. Put_Mouse_Message(VK_RBUTTON, x, y, true);
  648. Put_Mouse_Message(VK_RBUTTON, x, y);
  649. Put_Mouse_Message(VK_RBUTTON, x, y, true);
  650. processed = true;
  651. break;
  652. /*
  653. ** If the message is not pertinant to the keyboard system,
  654. ** then do nothing.
  655. */
  656. default:
  657. break;
  658. }
  659. /*
  660. ** If this message has been processed, then pass it on to the system
  661. ** directly.
  662. */
  663. if (processed) {
  664. DefWindowProc(window, message, wParam, lParam);
  665. return(true);
  666. }
  667. return(false);
  668. }
  669. /***********************************************************************************************
  670. * WWKeyboardClass::Available_Buffer_Room -- Fetch the quantity of free elements in the keyboa *
  671. * *
  672. * This examines the keyboard buffer queue and determine how many elements are available *
  673. * for use before the buffer becomes full. Typical use of this would be when inserting *
  674. * mouse events that require more than one element. Such an event must detect when there *
  675. * would be insufficient room in the buffer and bail accordingly. *
  676. * *
  677. * INPUT: none *
  678. * *
  679. * OUTPUT: Returns with the number of elements that may be stored in to the keyboard buffer *
  680. * before it becomes full and cannot accept any more elements. *
  681. * *
  682. * WARNINGS: none *
  683. * *
  684. * HISTORY: *
  685. * 11/02/1996 JLB : Created. *
  686. *=============================================================================================*/
  687. int WWKeyboardClass::Available_Buffer_Room(void) const
  688. {
  689. int avail = 0;
  690. if (Head == Tail) {
  691. avail = ARRAY_SIZE(Buffer);
  692. }
  693. if (Head < Tail) {
  694. avail = Tail - Head;
  695. }
  696. if (Head > Tail) {
  697. avail = (Tail + ARRAY_SIZE(Buffer)) - Head;
  698. }
  699. return(avail);
  700. }