KEY.CPP 40 KB

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