home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Education
/
collectionofeducationcarat1997.iso
/
COMPUSCI
/
TOT11.ZIP
/
TOTDOC11.ZIP
/
CHAPT6.TXT
< prev
next >
Wrap
Text File
|
1991-02-11
|
44KB
|
1,062 lines
Keyboard
&
Mouse
Input
"The computer is down. I hope it's something serious."
Stanton Delaplane
The totINPUT unit includes two objects for managing the mouse and key-
board. KeyOBJ is the main object for determining mouse and keyboard
activity. MouseOBJ controls the location and shape of the mouse cursor.
Mouse support is provided for Microsoft two-button, Logitech three-
button, and 100% compatible mice.
Getting Keyboard and Mouse Input
totINPUT includes a global instance KEY of type KeyOBJ. In the same way
that the instance SCREEN is used for all screen writes, the KEY
instance should be used for all keyboard and mouse polling. Key
includes methods for determining which key or mouse button was pressed,
checking the status of the Alt/Ctrl/Shift keys, controlling the
Num/Scroll/Caps lock keys, setting the keyboard repeat rate, and
stuffing the keyboard buffer.
There are also two special user hooks which provide easy ways to cus-
tomize your program. The idle hook allows you to perform some action
(like displaying a ticking clock) while the program is idle waiting for
user input. The character hook allows you to intercept every user
action, and is called every time a key is pressed or a mouse button is
clicked.
Setting Mouse Methods
Users of TechnoJock's Turbo Toolkit (TTT) may recall that the input
routines supported an "invisible" mouse cursor. If the user moved the
mouse while a program was waiting for a key press, a special code was
returned which indicated that the mouse had been moved either up, down,
left or right. Most of the TTT units would respond to the mouse move-
ment as though a cursor key had been pressed.
TechnoJock's Object Toolkit provides much more extensive mouse support.
However, if you want to make your programs respond like the original
TTT, you can with the following SetMouseMethod method:
SetMouseMethod(Method:byte);
6-2 User's Guide
--------------------------------------------------------------------------------
This method instructs the Toolkit on which form of mouse support to
provide. If a 0 is passed, or if there is no mouse detected, the object
will ignore any mouse activity. If a 1 is passed, an "invisible" mouse
will be supported, and if a 2 is passed, full mouse support is enabled.
If you want to temporarily disable mouse support, set the mouse method
to 0, which can later be set back to 1 or 2.
When the mouse method is set to 1, the following two methods control
how much the mouse must be moved before the movement is detected:
SetHoriz(Sensitivity:byte);
This method is passed the number of characters that the mouse cursor
must be moved horizontally before a MouseLeft or MouseRight code is
returned.
SetVert(Sensitivity:byte);
This method is passed the number of characters that the mouse cursor
must be moved vertically before a MouseUp or MouseDown code is
returned.
Determining User Input
The heart of the KeyOBJ object is the GetInput method. GetInput pauses
program execution and waits for the user to press a key, or click a
mouse button (or move the mouse, if the MouseMethod is set to 1). The
user action can be determined by calling the functions Lastkey, LastX
and LastY. These functions return the key/button(s) which were pressed,
and the (X,Y) location of the mouse when the action took place, respec-
tively.
Another method, GetKey, automatically calls GetInput, and returns the
user action code -- this saves calling GetInput followed by LastKey.
The method DelayKey is like GetInput, but will only pause for user
input for a specified number of milliseconds. This method is useful for
displaying temporary messages and the like. If a key has not been
pressed after a specified time period, Lastkey is updated with a value
of 0.
Unlike Turbo Pascal, the Toolkit uses a WORD sized variable to record
the user activity. As well as supporting the standard keyboard, KeyOBJ
reports mouse button activity, as well as many special key combina-
tions, e.g. Alt-TAB. Refer to table 6.1 for a full list of the KeyOBJ
action codes. Some of the action codes listed in the table are raised
Keyboard & Mouse 6-3
--------------------------------------------------------------------------------
by totWIN objects which indicate that the mouse was clicked on a spe-
cial window icon. Refer to chapter 7: Using Windows for further infor-
mation.
6-4 User's Guide
--------------------------------------------------------------------------------
Table 6.1
Key Action Codes
Key Norm Shift Alt Ctrl Key Norm Shift Alt Ctrl
a 97 65 286 1 F1 315 340 360 350
b 98 66 304 2 F2 316 341 361 351
c 99 67 302 3 F3 317 342 362 352
d 100 68 288 4 F4 318 343 363 353
e 101 69 274 5 F5 319 344 364 354
f 102 70 289 6 F6 320 345 365 355
g 103 71 290 7 F7 321 346 366 356
h 104 72 291 8 F8 322 347 367 357
i 105 73 279 9 F9 323 348 368 358
j 106 74 292 10 F10 324 349 369 359
k 107 75 293 11 F11 389 391 395 393
l 108 76 294 12 F12 390 392 396 394
m 109 77 306 13
n 110 78 305 14 BkSp 8 8 270 127
o 111 79 280 15 Up 328 428 408 397
p 112 80 281 16 Down 336 436 416 401
q 113 81 272 17 Left 331 431 411 371
r 114 82 275 18 Right 333 433 413 372
s 115 83 287 19 End 335 435 415 373
t 116 84 276 20 Home 327 427 407 375
u 117 85 278 21 PgUp 329 429 409 388
v 118 86 303 22 PgDn 337 437 417 374
w 119 87 273 23 Ins 338 261 418 260
x 120 88 301 24 Del 339 263 419 262
y 121 89 277 25 Tab 9 271 421 404
z 122 90 300 26 Esc 27 27 257 27
Enter 13 13 284 10
1 ! 49 33 376 -
2 @ 50 64 377 259 , < 44 60 307 -
3 # 51 35 378 - . > 46 62 308 -
4 $ 52 36 379 - / ? 47 63 309 -