home *** CD-ROM | disk | FTP | other *** search
- program TestKeyboardMouse;
-
- { This Turbo Pascal program illustrates how to use the KB Mouse
- bit flags in an application.
-
- KBM.COM must be executed before running this program. }
-
- const
- KeyBits = $4f0;
- ContFlag = $4f1;
- InstFlag = $4f2;
- var
- x, y, k : byte;
- AStr : char;
-
- Procedure CheckIfKBMInstalled;
- begin
- if (Memw[$0000:InstFlag] <> $1234) then begin
- Write(^G,'KBM has not been installed!');
- Halt;
- end;
- end; { Procedure check if KBM installed }
-
- procedure SetCursor(TopLine, BotLine : byte);
- type
- Regs = record
- ax, bx, cx, dx, bp, si, di, ds, es, flags : integer;
- end;
- var
- R : Regs;
- begin
- r.ax:=1 shl 8 + 0;
- r.cx:=TopLine shl 8 + BotLine;
- intr($10,R);
- end; { Procedure set cursor lines }
-
- Procedure Setup;
- begin
- CheckIfKBMInstalled;
- Mem[$0000:ContFlag]:=1; { kb mouse keys will NOT be read as
- normal keystrokes! }
- X:=40; Y:=12; AStr:=' ';
- TextMode; ClrScr;
- SetCursor(0,15); { use a large cursor for kb mouse pointer }
- WriteLn('Use arrow keys to move the cursor');
- WriteLn('[Home] [PgUp] and [-] are mouse ''buttons''');
- WriteLn('Press [CapsLock] to accelerate');
- WriteLn('Press [Esc] to exit the loop');
- end; { Procedure setup }
-
- Procedure Exit;
- begin
- Mem[$0000:ContFlag]:=0; { Reset to normal key processing }
- SetCursor(10,11); { Reset to normal cursor }
- end; { Procedure exit }
-
- Procedure MoveCursorAndSenseKBMButtons;
- var
- CapsLock : boolean;
- begin
- Repeat
- GotoXY(x,y); { move cursor to new position }
- k:=Mem[$0000:KeyBits]; { read the bit flags for the kb mouse }
-
- CapsLock:=(k and 128) <> 0;
- if CapsLock then Delay(25) { Short delay }
- else Delay(50); { Longer delay }
- if CapsLock then k:=k xor 128; { Clear capslock bit }
-
- case K of { Move cursor pointer, if necessary }
- 1 : { up } y:=y-1;
- 2 : { right } x:=x+1;
- 4 : { down } y:=y+1;
- 8 : { left } x:=x-1;
- end;
-
- if (x>80) then x:=1 else if (x<1) then x:=80; { Adjust cursor to }
- if (y>24) then y:=1 else if (Y<1) then y:=24; { wrap around screen }
-
- case K of { Read mouse buttons, react appropriately }
- 16 : { Button 1 = [Home] } begin
- Sound(200); Delay(100); NoSound; end;
- 32 : { Button 2 = [PgUp] } begin
- Sound(400); Delay(100); NoSound; end;
- 64 : { Button 3 = [-] (grey minus) } begin
- Sound(600); Delay(100); NoSound; end;
- end;
-
- if KeyPressed then Read(kbd,AStr);
- until (AStr=#27); { Exit loop on [Esc] }
- end; { Procedure move cursor and sense KBM buttons }
-
- BEGIN
- Setup;
- MoveCursorAndSenseKBMButtons;
- Exit;
- END. { program Test keyboard mouse }