DMOUSE.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. /*
  2. * Seven Kingdoms: Ancient Adversaries
  3. *
  4. * Copyright 1997,1998 Enlight Software Ltd.
  5. *
  6. * This program is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. *
  19. */
  20. /***********************************************************************
  21. *
  22. * DMOUSE.VXD - DirectMouse
  23. *
  24. * this VxD lets a Win32 app get direct mouse input, without the windows
  25. * user interface filtering/mapping them.
  26. *
  27. * multiple apps can open DMOUSE.VXD, but it is assumes only
  28. * one app will be talking to DMOUSE at a time.
  29. *
  30. * example:
  31. * #include "dmouse.h"
  32. * h = DMouseOpen();
  33. * ....
  34. *
  35. * DMOUSE_STATE dm;
  36. * DMouseGetState(h, &dm);
  37. *
  38. * if (dm.mouse_dx || dm.mouse_dy)
  39. * mouse has moved
  40. *
  41. * if (dm.mouse_state & MOUSE_BUTTON_DOWN_MASK)
  42. * mouse has gone down (from last call)
  43. *
  44. * if (dm.mouse_state & MOUSE_BUTTON_UP_MASK)
  45. * mouse has gone up (from last call)
  46. *
  47. * if (dm.mouse_state & MOUSE_BUTTON_ASYNC_MASK)
  48. * a mouse button is down now!
  49. *
  50. * ....
  51. * DMouseClose(h);
  52. *
  53. * ToddLa
  54. *
  55. ***********************************************************************/
  56. #ifndef __WINDOWS_
  57. #include <windows.h>
  58. #endif
  59. #define DMOUSE_VXD "\\\\.\\DMOUSE.VXD"
  60. #define DMOUSE_GET_STATE 1
  61. #define DMOUSE_GET_STATE_PTR 2
  62. /***********************************************************************
  63. * DMOUSE_STATE
  64. *
  65. * mouse_dx - delta (in mickeys) that the mouse has moved in x
  66. * mouse_dy - delta (in mickeys) that the mouse has moved in y
  67. * mouse_state - contains the current state of the mouse buttons
  68. * contains the buttons that have gone up (from last query)
  69. * contains the buttons that have gone down (from last query)
  70. *
  71. ***********************************************************************/
  72. struct DMOUSE_STATE
  73. {
  74. DWORD mouse_delta_x;
  75. DWORD mouse_delta_y;
  76. DWORD mouse_state;
  77. };
  78. #define MOUSE_STATE_CHANGE 0x80000000
  79. #define MOUSE_BUTTON_ASYNC_MASK 0x0000000F
  80. #define MOUSE_BUTTON1_ASYNC 0x00000008
  81. #define MOUSE_BUTTON2_ASYNC 0x00000004
  82. #define MOUSE_BUTTON3_ASYNC 0x00000002
  83. #define MOUSE_BUTTON4_ASYNC 0x00000001
  84. #define MOUSE_BUTTON_DOWN_MASK 0x00000F00
  85. #define MOUSE_BUTTON1_DOWN 0x00000800
  86. #define MOUSE_BUTTON2_DOWN 0x00000400
  87. #define MOUSE_BUTTON3_DOWN 0x00000200
  88. #define MOUSE_BUTTON4_DOWN 0x00000100
  89. #define MOUSE_BUTTON_UP_MASK 0x0000F000
  90. #define MOUSE_BUTTON1_UP 0x00008000
  91. #define MOUSE_BUTTON2_UP 0x00004000
  92. #define MOUSE_BUTTON3_UP 0x00002000
  93. #define MOUSE_BUTTON4_UP 0x00001000
  94. /***********************************************************************
  95. *
  96. * DMouseOpen
  97. *
  98. * open a instance of the DMOUSE VxD and return you a handle
  99. *
  100. ***********************************************************************/
  101. __inline HANDLE DMouseOpen()
  102. {
  103. HANDLE h;
  104. h = CreateFile(DMOUSE_VXD, GENERIC_READ, FILE_SHARE_READ, NULL,
  105. OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_DELETE_ON_CLOSE, NULL);
  106. if (h == INVALID_HANDLE_VALUE)
  107. return NULL;
  108. return h;
  109. }
  110. /***********************************************************************
  111. *
  112. * DMouseClose
  113. *
  114. * close a instance of the DMOUSE VxD
  115. *
  116. ***********************************************************************/
  117. __inline void DMouseClose(HANDLE h)
  118. {
  119. if (h != NULL && h != INVALID_HANDLE_VALUE)
  120. CloseHandle(h);
  121. }
  122. /***********************************************************************
  123. *
  124. * DMouseGetState
  125. *
  126. * read the current mouse state.
  127. *
  128. * this will return the amount the mouse has moved from the last time
  129. * you called this service. (mouse_delta_x, mouse_delta_y)
  130. *
  131. * if a button has gone down from the last time you called this
  132. * service the associated bit (MOUSE_BUTTONx_DOWN) will be set in
  133. * mouse_state
  134. *
  135. * if a button has gone up from the last time you called this
  136. * service the associated bit (MOUSE_BUTTONx_UP) will be set in
  137. * mouse_state
  138. *
  139. * if a button is down right now the associated bit (MOUSE_BUTTONx_ASYNC)
  140. * will be set in mouse_state
  141. *
  142. ***********************************************************************/
  143. __inline BOOL DMouseGetState(HANDLE h, DMOUSE_STATE *p)
  144. {
  145. DWORD cb;
  146. if (h == NULL || h == INVALID_HANDLE_VALUE)
  147. return FALSE;
  148. return DeviceIoControl(h, DMOUSE_GET_STATE,
  149. NULL, 0, p, sizeof(DMOUSE_STATE), &cb, 0);
  150. }
  151. /***********************************************************************
  152. *
  153. * DMouseGetStatePointer
  154. *
  155. * returns a pointer to the internal "live" MOUSE_STATE
  156. *
  157. * in general it is better to use DMouseGetState, but this
  158. * service is useful for "peeking" at the button state quickly
  159. *
  160. * to determine if the mouse state has changed, you need to look
  161. * at the MOUSE_STATE_CHANGE bit in mouse_state.
  162. *
  163. ***********************************************************************/
  164. __inline DMOUSE_STATE * DMouseGetStatePointer(HANDLE h)
  165. {
  166. DWORD cb;
  167. DMOUSE_STATE *p = NULL;
  168. if (h == NULL || h == INVALID_HANDLE_VALUE)
  169. return NULL;
  170. DeviceIoControl(h, DMOUSE_GET_STATE_PTR,
  171. NULL, 0, &p, sizeof(p), &cb, 0);
  172. return p;
  173. }