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