msmouse.tex 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419
  1. %
  2. % $Id$
  3. % This file is part of the FPC documentation.
  4. % Copyright (C) 1997, by Michael Van Canneyt
  5. %
  6. % The FPC documentation is free text; you can redistribute it and/or
  7. % modify it under the terms of the GNU Library General Public License as
  8. % published by the Free Software Foundation; either version 2 of the
  9. % License, or (at your option) any later version.
  10. %
  11. % The FPC Documentation 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 GNU
  14. % Library General Public License for more details.
  15. %
  16. % You should have received a copy of the GNU Library General Public
  17. % License along with the FPC documentation; see the file COPYING.LIB. If not,
  18. % write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  19. % Boston, MA 02111-1307, USA.
  20. %
  21. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  22. %
  23. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  24. % The MSMouse unit
  25. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  26. \chapter{The MsMouse unit}
  27. \FPCexampledir{mmouseex}
  28. The msmouse unit provides basic mouse handling under \dos (Go32v1 and Go32v2)
  29. Some general remarks about the msmouse unit:
  30. \begin{itemize}
  31. \item For maximum portability, it is advisable to use the \file{mouse} unit;
  32. that unit is portable across platforms, and offers a similar interface.
  33. Under no circumstances should the two units be used together.
  34. \item The mouse driver does not know when the text screen scrolls. This results
  35. in unerased mouse cursors on the screen when the screen scrolls while the
  36. mouse cursor is visible. The solution is to hide the mouse cursor (using
  37. HideMouse) when you write something to the screen and to show it again
  38. afterwards (using ShowMouse).
  39. \item All Functions/Procedures that return and/or accept coordinates of the mouse
  40. cursor, always do so in pixels and zero based (so the upper left corner of
  41. the screen is (0,0)). To get the (column, row) in standard text mode, divide
  42. both x and y by 8 (and add 1 if you want to have it 1 based).
  43. \item The real resolution of graphic modes and the one the mouse driver uses can
  44. differ. For example, mode 13h (320*200 pixels) is handled by the mouse driver
  45. as 640*200, so you will have to multiply the X coordinates you give to the
  46. driver and divide the ones you get from it by 2 in that mode.
  47. \item By default the msmouse unit is compiled with the conditional define
  48. MouseCheck. This causes every procedure/function of the unit to check the
  49. MouseFound variable prior to doing anything. Of course this is not necessary,
  50. so if you are sure you are not calling any mouse unit procedures when no
  51. mouse is found, you can recompile the mouse unit without this conditional
  52. define.
  53. \item
  54. You will notice that several procedures/functions have longint sized
  55. parameters while only the lower 16 bits are used. This is because FPC is
  56. a 32 bit compiler and consequently 32 bit parameters result in faster code.
  57. \end{itemize}
  58. \section{Constants, types and variables}
  59. The following constants are defined (to be used in e.g. the
  60. \seef{GetLastButtonPress} call).
  61. \begin{verbatim}
  62. LButton = 1; {left button}
  63. RButton = 2; {right button}
  64. MButton = 4; {middle button}
  65. \end{verbatim}
  66. The following variable exist:
  67. \begin{verbatim}
  68. MouseFound: Boolean;
  69. \end{verbatim}
  70. it is set to \var{True} or \var{False} in the unit's initialization code.
  71. \section{Functions and procedures}
  72. \begin{function}{GetLastButtonPress}
  73. \Declaration
  74. Function GetLastButtonPress (Button: Longint; Var x,y:Longint) : Longint;
  75. \Description
  76. \var{GetLastButtonPress}
  77. Stores the position where \var{Button} was last pressed in \var{x} and
  78. \var{y} and returns
  79. the number of times this button has been pressed since the last call to this
  80. function with \var{Button} as parameter. For \var{Button} you can use the
  81. \var{LButton}, \var{RButton} and \var{MButton} constants for resp. the left,
  82. right and middle button.
  83. With certain mouse drivers, checking the middle button when using a
  84. two-button mouse to gives and clears the stats of the right button.
  85. \Errors
  86. None.
  87. \SeeAlso
  88. \seef{GetLastButtonRelease}
  89. \end{function}
  90. \FPCexample{mouse5}
  91. \begin{function}{GetLastButtonRelease}
  92. \Declaration
  93. Function GetLastButtonRelease (Button: Longint; Var x,y:Longint) : Longint;
  94. \Description
  95. \var{GetLastButtonRelease}
  96. stores the position where \var{Button} was last released in \var{x} and
  97. \var{y} and returns
  98. the number of times this button has been released since the last call to this
  99. function with \var{Button} as parameter. For button you can use the
  100. \var{LButton}, \var{RButton} and \var{MButton} constants for resp.
  101. the left, right and middle button.
  102. With certain mouse drivers, checking the middle button when using a
  103. two-button mouse to gives and clears the stats of the right button.
  104. \Errors
  105. None.
  106. \SeeAlso
  107. \seef{GetLastButtonPress}
  108. \end{function}
  109. For an example, see \seef{GetLastButtonPress}.
  110. \begin{procedure}{GetMouseState}
  111. \Declaration
  112. Procedure GetMouseState (Var x, y, buttons: Longint);
  113. \Description
  114. \var{GetMouseState} Returns information on the current mouse position
  115. and which buttons are currently pressed.
  116. \var{x} and \var{y} return the mouse cursor coordinates in pixels.
  117. \var{Buttons} is a bitmask. Check the example program to see how you can get the
  118. necessary information from it.
  119. \Errors
  120. None.
  121. \SeeAlso
  122. \seef{LPressed}, \seef{MPressed}, \seef{RPressed},
  123. \seep{SetMousePos}
  124. \end{procedure}
  125. \FPCexample{mouse3}
  126. \begin{procedure}{HideMouse}
  127. \Declaration
  128. Procedure HideMouse ;
  129. \Description
  130. \var{HideMouse} makes the mouse cursor invisible.
  131. Multiple calls to HideMouse will require just as many calls to ShowMouse to
  132. make the mouse cursor visible again.
  133. \Errors
  134. None.
  135. \SeeAlso
  136. \seep{ShowMouse}, \seep{SetMouseHideWindow}
  137. \end{procedure}
  138. For an example, see \seep{ShowMouse}.
  139. \begin{procedure}{InitMouse}
  140. \Declaration
  141. Procedure InitMouse ;
  142. \Description
  143. \var{InitMouse}
  144. Initializes the mouse driver sets the variable \var{MouseFound} depending on
  145. whether or not a mouse is found.
  146. This is Automatically called at the start of your program.
  147. You should never have to call it, unless you want to reset everything to
  148. its default values.
  149. \Errors
  150. None.
  151. \SeeAlso
  152. \var{MouseFound} variable.
  153. \end{procedure}
  154. \FPCexample{mouse1}
  155. \begin{function}{LPressed}
  156. \Declaration
  157. Function LPressed : Boolean;
  158. \Description
  159. \var{LPressed} returns \var{True} if the left mouse button is pressed.
  160. This is simply a wrapper for the GetMouseState procedure.
  161. \Errors
  162. None.
  163. \SeeAlso
  164. \seep{GetMouseState}, \seef{MPressed}, \seef{RPressed}
  165. \end{function}
  166. For an example, see \seep{GetMouseState}.
  167. \begin{function}{MPressed}
  168. \Declaration
  169. Function MPressed : Boolean;
  170. \Description
  171. \var{MPressed} returns \var{True} if the middle mouse button is pressed.
  172. This is simply a wrapper for the GetMouseState procedure.
  173. \Errors
  174. None.
  175. \SeeAlso
  176. \seep{GetMouseState}, \seef{LPressed}, \seef{RPressed}
  177. \end{function}
  178. For an example, see \seep{GetMouseState}.
  179. \begin{function}{RPressed}
  180. \Declaration
  181. Function RPressed : Boolean;
  182. \Description
  183. \var{RPressed} returns \var{True} if the right mouse button is pressed.
  184. This is simply a wrapper for the GetMouseState procedure.
  185. \Errors
  186. None.
  187. \SeeAlso
  188. \seep{GetMouseState}, \seef{LPressed}, \seef{MPressed}
  189. \end{function}
  190. For an example, see \seep{GetMouseState}.
  191. \begin{procedure}{SetMouseAscii}
  192. \Declaration
  193. Procedure SetMouseAscii (Ascii: Byte);
  194. \Description
  195. \var{SetMouseAscii}
  196. sets the \var{Ascii} value of the character that depicts the mouse cursor in
  197. text mode.
  198. The difference between this one and \seep{SetMouseShape}, is that the foreground
  199. and background colors stay the same and that the Ascii code you enter is the
  200. character that you will get on screen; there's no XOR'ing.
  201. \Errors
  202. None
  203. \SeeAlso
  204. \seep{SetMouseShape}
  205. \end{procedure}
  206. \FPCexample{mouse8}
  207. \begin{procedure}{SetMouseHideWindow}
  208. \Declaration
  209. Procedure SetMouseHideWindow (xmin,ymin,xmax,ymax: Longint);
  210. \Description
  211. \var{SetMouseHideWindow}
  212. defines a rectangle on screen with top-left corner at (\var{xmin,ymin}) and
  213. botto-right corner at (\var{xmax,ymax}),which causes the mouse cursor to be
  214. turned off when it is moved into it.
  215. When the mouse is moved into the specified region, it is turned off until you
  216. call \var{ShowMouse} again. However, once you've called \seep{ShowMouse}, you'll have to
  217. call \var{SetMouseHideWindow} again to redefine the hide window...
  218. This may be annoying, but it's the way it's implemented in the mouse driver.
  219. While \var{xmin, ymin, xmax} and \var{ymax} are Longint parameters,
  220. only the lower 16 bits are used.
  221. Warning: it seems Win98 SE doesn't (properly) support this function,
  222. maybe this already the case with earlier versions too!
  223. \Errors
  224. None.
  225. \SeeAlso
  226. \seep{ShowMouse}, \seep{HideMouse}
  227. \end{procedure}
  228. \FPCexample{mouse9}
  229. \begin{procedure}{SetMousePos}
  230. \Declaration
  231. Procedure SetMousePos (x,y:Longint);
  232. \Description
  233. \var{SetMosusePos} sets the position of the mouse cursor on the screen.
  234. \var{x} is the horizontal position in pixels, \var{y} the vertical position
  235. in pixels. The upper-left hand corner of the screen is the origin.
  236. While \var{x} and \var{y} are longints, only the lower 16 bits are used.
  237. \Errors
  238. None.
  239. \SeeAlso
  240. \seep{GetMouseState}
  241. \end{procedure}
  242. \FPCexample{mouse4}
  243. \begin{procedure}{SetMouseShape}
  244. \Declaration
  245. Procedure SetMouseShape (ForeColor,BackColor,Ascii: Byte);
  246. \Description
  247. \var{SetMouseShape}
  248. defines how the mouse cursor looks in textmode
  249. The character and its attributes that are on the mouse cursor's position on
  250. screen are XOR'ed with resp. \var{ForeColor}, \var{BackColor} and
  251. \var{Ascii}. Set them all to 0 for a "transparent" cursor.
  252. \Errors
  253. None.
  254. \SeeAlso
  255. \seep{SetMouseAscii}
  256. \end{procedure}
  257. \FPCexample{mouse7}
  258. \begin{procedure}{SetMouseSpeed}
  259. \Declaration
  260. Procedure SetMouseSpeed (Horizontal, Vertical: Longint);
  261. \Description
  262. \var{SetMouseSpeed} sets the mouse speed in mickeys per 8 pixels.
  263. A mickey is the smallest measurement unit handled by a mouse. With this
  264. procedure you can set how many mickeys the mouse should move to move the
  265. cursor 8 pixels horizontally of vertically. The default values are 8 for
  266. horizontal and 16 for vertical movement.
  267. While this procedure accepts longint parameters, only the low 16 bits are
  268. actually used.
  269. \Errors
  270. None.
  271. \SeeAlso
  272. \end{procedure}
  273. \FPCexample{mouse10}
  274. \begin{procedure}{SetMouseWindow}
  275. \Declaration
  276. Procedure SetMouseWindow (xmin,ymin,xmax,ymax: Longint);
  277. \Description
  278. \var{SetMousWindow}
  279. defines a rectangle on screen with top-left corner at (\var{xmin,ymin}) and
  280. bottom-right corner at (\var{xmax,ymax}), out of which the mouse
  281. cursor can't move.
  282. This procedure is simply a wrapper for the \seep{SetMouseXRange} and
  283. \seep{SetMouseYRange} procedures.
  284. While \var{xmin, ymin, xmax} and \var{ymax} are Longint parameters,
  285. only the lower 16 bits are used.
  286. \Errors
  287. None.
  288. \SeeAlso
  289. \seep{SetMouseXRange}, \seep{SetMouseYRange}
  290. \end{procedure}
  291. For an example, see \seep{SetMouseXRange}.
  292. \begin{procedure}{SetMouseXRange}
  293. \Declaration
  294. Procedure SetMouseXRange (Min, Max: Longint);
  295. \Description
  296. \var{SetMouseXRange}
  297. sets the minimum (\var{Min}) and maximum (\var{Max}) horizontal coordinates in between which the
  298. mouse cursor can move.
  299. While \var{Min} and \var{Max} are Longint parameters, only the lower 16 bits
  300. are used.
  301. \Errors
  302. None.
  303. \SeeAlso
  304. \seep{SetMouseYRange}, \seep{SetMouseWindow}
  305. \end{procedure}
  306. \FPCexample{mouse6}
  307. \begin{procedure}{SetMouseYRange}
  308. \Declaration
  309. Procedure SetMouseYRange (Min, Max: Longint);
  310. \Description
  311. \var{SetMouseYRange}
  312. sets the minimum (\var{Min}) and maximum (\var{Max}) vertical coordinates in between which the
  313. mouse cursor can move.
  314. While \var{Min} and \var{Max} are Longint parameters, only the lower 16 bits
  315. are used.
  316. \Errors
  317. None.
  318. \SeeAlso
  319. \seep{SetMouseXRange}, \seep{SetMouseWindow}
  320. \end{procedure}
  321. For an example, see \seep{SetMouseXRange}.
  322. \begin{procedure}{ShowMouse}
  323. \Declaration
  324. Procedure ShowMouse ;
  325. \Description
  326. \var{ShowMouse} makes the mouse cursor visible.
  327. At the start of your progam, the mouse cursor is invisible.
  328. \Errors
  329. None.
  330. \SeeAlso
  331. \seep{HideMouse},\seep{SetMouseHideWindow}
  332. \end{procedure}
  333. \FPCexample{mouse2}