msmouse.tex 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417
  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 writing 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 it must be 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 the X coordinates given to the
  46. driver must be multiplied by 2 and divided by 2 when the return from the
  47. driver in that mode.
  48. \item By default the msmouse unit is compiled with the conditional define
  49. MouseCheck. This causes every procedure/function of the unit to check the
  50. MouseFound variable prior to doing anything. Of course this is not necessary,
  51. so when proper checking is added to the calling program, this define may be
  52. removed and the unit can be recompiled.
  53. \item Several procedures/functions have longint sized parameters while only
  54. the lower 16 bits are used. This is because FPC is a 32 bit compiler and
  55. consequently 32 bit parameters result in faster code.
  56. \end{itemize}
  57. \section{Constants, types and variables}
  58. The following constants are defined (to be used in e.g. the
  59. \seef{GetLastButtonPress} call).
  60. \begin{verbatim}
  61. LButton = 1; {left button}
  62. RButton = 2; {right button}
  63. MButton = 4; {middle button}
  64. \end{verbatim}
  65. The following variable exist:
  66. \begin{verbatim}
  67. MouseFound: Boolean;
  68. \end{verbatim}
  69. it is set to \var{True} or \var{False} in the unit's initialization code.
  70. \section{Functions and procedures}
  71. \begin{function}{GetLastButtonPress}
  72. \Declaration
  73. Function GetLastButtonPress (Button: Longint; Var x,y:Longint) : Longint;
  74. \Description
  75. \var{GetLastButtonPress}
  76. Stores the position where \var{Button} was last pressed in \var{x} and
  77. \var{y} and returns
  78. the number of times this button has been pressed since the last call to this
  79. function with \var{Button} as parameter. For \var{Button} the
  80. \var{LButton}, \var{RButton} and \var{MButton} constants can be used for resp. the left,
  81. right and middle button.
  82. With certain mouse drivers, checking the middle button when using a
  83. two-button mouse to gives and clears the stats of the right button.
  84. \Errors
  85. None.
  86. \SeeAlso
  87. \seef{GetLastButtonRelease}
  88. \end{function}
  89. \FPCexample{mouse5}
  90. \begin{function}{GetLastButtonRelease}
  91. \Declaration
  92. Function GetLastButtonRelease (Button: Longint; Var x,y:Longint) : Longint;
  93. \Description
  94. \var{GetLastButtonRelease}
  95. stores the position where \var{Button} was last released in \var{x} and
  96. \var{y} and returns
  97. the number of times this button has been released since the last call to this
  98. function with \var{Button} as parameter. For button the
  99. \var{LButton}, \var{RButton} and \var{MButton} constants can be used for resp.
  100. the left, right and middle button.
  101. With certain mouse drivers, checking the middle button when using a
  102. two-button mouse to gives and clears the stats of the right button.
  103. \Errors
  104. None.
  105. \SeeAlso
  106. \seef{GetLastButtonPress}
  107. \end{function}
  108. For an example, see \seef{GetLastButtonPress}.
  109. \begin{procedure}{GetMouseState}
  110. \Declaration
  111. Procedure GetMouseState (Var x, y, buttons: Longint);
  112. \Description
  113. \var{GetMouseState} Returns information on the current mouse position
  114. and which buttons are currently pressed.
  115. \var{x} and \var{y} return the mouse cursor coordinates in pixels.
  116. \var{Buttons} is a bitmask. Check the example program to see how to get the
  117. necessary information from it.
  118. \Errors
  119. None.
  120. \SeeAlso
  121. \seef{LPressed}, \seef{MPressed}, \seef{RPressed},
  122. \seep{SetMousePos}
  123. \end{procedure}
  124. \FPCexample{mouse3}
  125. \begin{procedure}{HideMouse}
  126. \Declaration
  127. Procedure HideMouse ;
  128. \Description
  129. \var{HideMouse} makes the mouse cursor invisible.
  130. Multiple calls to HideMouse will require just as many calls to ShowMouse to
  131. make the mouse cursor visible again.
  132. \Errors
  133. None.
  134. \SeeAlso
  135. \seep{ShowMouse}, \seep{SetMouseHideWindow}
  136. \end{procedure}
  137. For an example, see \seep{ShowMouse}.
  138. \begin{procedure}{InitMouse}
  139. \Declaration
  140. Procedure InitMouse ;
  141. \Description
  142. \var{InitMouse}
  143. Initializes the mouse driver sets the variable \var{MouseFound} depending on
  144. whether or not a mouse is found. This is Automatically called at the start of
  145. a program. Normally it should never be called, unless everything should be
  146. reset to its default values.
  147. \Errors
  148. None.
  149. \SeeAlso
  150. \var{MouseFound} variable.
  151. \end{procedure}
  152. \FPCexample{mouse1}
  153. \begin{function}{LPressed}
  154. \Declaration
  155. Function LPressed : Boolean;
  156. \Description
  157. \var{LPressed} returns \var{True} if the left mouse button is pressed.
  158. This is simply a wrapper for the GetMouseState procedure.
  159. \Errors
  160. None.
  161. \SeeAlso
  162. \seep{GetMouseState}, \seef{MPressed}, \seef{RPressed}
  163. \end{function}
  164. For an example, see \seep{GetMouseState}.
  165. \begin{function}{MPressed}
  166. \Declaration
  167. Function MPressed : Boolean;
  168. \Description
  169. \var{MPressed} returns \var{True} if the middle mouse button is pressed.
  170. This is simply a wrapper for the GetMouseState procedure.
  171. \Errors
  172. None.
  173. \SeeAlso
  174. \seep{GetMouseState}, \seef{LPressed}, \seef{RPressed}
  175. \end{function}
  176. For an example, see \seep{GetMouseState}.
  177. \begin{function}{RPressed}
  178. \Declaration
  179. Function RPressed : Boolean;
  180. \Description
  181. \var{RPressed} returns \var{True} if the right mouse button is pressed.
  182. This is simply a wrapper for the GetMouseState procedure.
  183. \Errors
  184. None.
  185. \SeeAlso
  186. \seep{GetMouseState}, \seef{LPressed}, \seef{MPressed}
  187. \end{function}
  188. For an example, see \seep{GetMouseState}.
  189. \begin{procedure}{SetMouseAscii}
  190. \Declaration
  191. Procedure SetMouseAscii (Ascii: Byte);
  192. \Description
  193. \var{SetMouseAscii}
  194. sets the \var{Ascii} value of the character that depicts the mouse cursor in
  195. text mode.
  196. The difference between this one and \seep{SetMouseShape}, is that the foreground
  197. and background colors stay the same and that the Ascii code entered is the
  198. character that will get on screen; there's no XOR'ing.
  199. \Errors
  200. None
  201. \SeeAlso
  202. \seep{SetMouseShape}
  203. \end{procedure}
  204. \FPCexample{mouse8}
  205. \begin{procedure}{SetMouseHideWindow}
  206. \Declaration
  207. Procedure SetMouseHideWindow (xmin,ymin,xmax,ymax: Longint);
  208. \Description
  209. \var{SetMouseHideWindow}
  210. defines a rectangle on screen with top-left corner at (\var{xmin,ymin}) and
  211. botto-right corner at (\var{xmax,ymax}),which causes the mouse cursor to be
  212. turned off when it is moved into it.
  213. When the mouse is moved into the specified region, it is turned off until
  214. call \var{ShowMouse} is called again. However, once \seep{ShowMouse} is
  215. called, \var{SetMouseHideWindow} must be called again to redefine the hide window...
  216. This may be annoying, but it's the way it's implemented in the mouse driver.
  217. While \var{xmin, ymin, xmax} and \var{ymax} are Longint parameters,
  218. only the lower 16 bits are used.
  219. Warning: it seems Win98 SE doesn't (properly) support this function,
  220. maybe this already the case with earlier versions too!
  221. \Errors
  222. None.
  223. \SeeAlso
  224. \seep{ShowMouse}, \seep{HideMouse}
  225. \end{procedure}
  226. \FPCexample{mouse9}
  227. \begin{procedure}{SetMousePos}
  228. \Declaration
  229. Procedure SetMousePos (x,y:Longint);
  230. \Description
  231. \var{SetMosusePos} sets the position of the mouse cursor on the screen.
  232. \var{x} is the horizontal position in pixels, \var{y} the vertical position
  233. in pixels. The upper-left hand corner of the screen is the origin.
  234. While \var{x} and \var{y} are longints, only the lower 16 bits are used.
  235. \Errors
  236. None.
  237. \SeeAlso
  238. \seep{GetMouseState}
  239. \end{procedure}
  240. \FPCexample{mouse4}
  241. \begin{procedure}{SetMouseShape}
  242. \Declaration
  243. Procedure SetMouseShape (ForeColor,BackColor,Ascii: Byte);
  244. \Description
  245. \var{SetMouseShape}
  246. defines how the mouse cursor looks in textmode
  247. The character and its attributes that are on the mouse cursor's position on
  248. screen are XOR'ed with resp. \var{ForeColor}, \var{BackColor} and
  249. \var{Ascii}. Set them all to 0 for a "transparent" cursor.
  250. \Errors
  251. None.
  252. \SeeAlso
  253. \seep{SetMouseAscii}
  254. \end{procedure}
  255. \FPCexample{mouse7}
  256. \begin{procedure}{SetMouseSpeed}
  257. \Declaration
  258. Procedure SetMouseSpeed (Horizontal, Vertical: Longint);
  259. \Description
  260. \var{SetMouseSpeed} sets the mouse speed in mickeys per 8 pixels.
  261. A mickey is the smallest measurement unit handled by a mouse. With this
  262. procedure one can set how many mickeys the mouse should move to move the
  263. cursor 8 pixels horizontally of vertically. The default values are 8 for
  264. horizontal and 16 for vertical movement.
  265. While this procedure accepts longint parameters, only the low 16 bits are
  266. actually used.
  267. \Errors
  268. None.
  269. \SeeAlso
  270. \end{procedure}
  271. \FPCexample{mouse10}
  272. \begin{procedure}{SetMouseWindow}
  273. \Declaration
  274. Procedure SetMouseWindow (xmin,ymin,xmax,ymax: Longint);
  275. \Description
  276. \var{SetMousWindow}
  277. defines a rectangle on screen with top-left corner at (\var{xmin,ymin}) and
  278. bottom-right corner at (\var{xmax,ymax}), out of which the mouse
  279. cursor can't move.
  280. This procedure is simply a wrapper for the \seep{SetMouseXRange} and
  281. \seep{SetMouseYRange} procedures.
  282. While \var{xmin, ymin, xmax} and \var{ymax} are Longint parameters,
  283. only the lower 16 bits are used.
  284. \Errors
  285. None.
  286. \SeeAlso
  287. \seep{SetMouseXRange}, \seep{SetMouseYRange}
  288. \end{procedure}
  289. For an example, see \seep{SetMouseXRange}.
  290. \begin{procedure}{SetMouseXRange}
  291. \Declaration
  292. Procedure SetMouseXRange (Min, Max: Longint);
  293. \Description
  294. \var{SetMouseXRange}
  295. sets the minimum (\var{Min}) and maximum (\var{Max}) horizontal coordinates in between which the
  296. mouse cursor can move.
  297. While \var{Min} and \var{Max} are Longint parameters, only the lower 16 bits
  298. are used.
  299. \Errors
  300. None.
  301. \SeeAlso
  302. \seep{SetMouseYRange}, \seep{SetMouseWindow}
  303. \end{procedure}
  304. \FPCexample{mouse6}
  305. \begin{procedure}{SetMouseYRange}
  306. \Declaration
  307. Procedure SetMouseYRange (Min, Max: Longint);
  308. \Description
  309. \var{SetMouseYRange}
  310. sets the minimum (\var{Min}) and maximum (\var{Max}) vertical coordinates in between which the
  311. mouse cursor can move.
  312. While \var{Min} and \var{Max} are Longint parameters, only the lower 16 bits
  313. are used.
  314. \Errors
  315. None.
  316. \SeeAlso
  317. \seep{SetMouseXRange}, \seep{SetMouseWindow}
  318. \end{procedure}
  319. For an example, see \seep{SetMouseXRange}.
  320. \begin{procedure}{ShowMouse}
  321. \Declaration
  322. Procedure ShowMouse ;
  323. \Description
  324. \var{ShowMouse} makes the mouse cursor visible.
  325. At the start of the program, the mouse cursor is invisible.
  326. \Errors
  327. None.
  328. \SeeAlso
  329. \seep{HideMouse},\seep{SetMouseHideWindow}
  330. \end{procedure}
  331. \FPCexample{mouse2}