KEY.CPP 40 KB

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