home *** CD-ROM | disk | FTP | other *** search
- Unit Mouser;
-
-
- {*****************************************************************************}
- { }
- { The Mouse Unit contains mouse routines to interface with different }
- { programs. It was written by Charles Hahn. }
- { }
- {*****************************************************************************}
-
-
- interface
-
- uses
- dos,
- crt;
-
- type
- mousemove = record
- xmouse : integer;
- ymouse : integer;
- end;
-
-
- var
- mousepresent : boolean;
- leftbutton : boolean;
- rightbutton : boolean;
- centerbutton : boolean;
- numberbutton : integer;
- lastmouse : mousemove;
-
- function mouseready : boolean;
-
- {This function returns whether the mouse and driver are present. }
- {It was written by Charles Hahn. }
-
- function mousebuttonpressed : boolean;
-
- {This function checks to see if a button has been pressed on the }
- {mouse. If a button has been pressed, the function will then set}
- {the correct boolean variable. It was written by Charles Hahn. }
-
- function questionmouse : boolean;
-
- {This function checks to see if the mouse has any information to }
- {pass to the calling program. It works like the KEYPRESSED }
- {function in TP. It was written by Charles Hahn }
-
- procedure mousemoved(var movement : mousemove);
-
- {This procedure reads the mouses movement counters and returns }
- {the x-y movement information. This information is not scaled in}
- {any way and the numbers returned are actual mickeys. It was }
- {written by Charles Hahn. }
-
-
- implementation
-
- function mouseready : boolean;
-
- var
- regs : registers;
- begin
- regs.ax := $0000; {AX = 0000H tests for presence of mouse and driver}
- intr($33, regs);
- if ((regs.AX and $FFFF) = $FFFF) then
- begin
- mousepresent := true; {if AX = FFFFH then the mouse is present and}
- numberbutton := regs.BX; {and BX contains the number of buttons}
- end {on the mouse.}
- else
- begin
- mousepresent := false;
- numberbutton := 0;
- end;
- mouseready := mousepresent;
- end;
-
- function mousebuttonpressed : boolean;
- var
- regs : registers;
- temp : word;
- begin
- regs.AX := $0005; {0005H gets button pressed information}
- regs.BX := $0007; {BX contains the identifier for the buttons to check}
- intr($33, regs);
- temp := (regs.AX and $0007);{the information is in the last 3 bits}
- leftbutton := ((temp and $0001) = $0001); {This means the left button is pressed}
- rightbutton := ((temp and $0002) = $0002); {This means the right button is pressed}
- centerbutton := ((temp and $0004) = $0004); {This means the center button is pressed}
- mousebuttonpressed := (leftbutton or rightbutton or centerbutton);
- {The result is true if any button has been pressed}
- end;
-
- function questionmouse : boolean;
- var
- regs : registers;
- begin
- regs.AX := $03; {Get mouse position and status}
- intr($33, regs);
- if (((regs.BX and $0007) > 0) or (lastmouse.xmouse <> regs.CX) or (lastmouse.ymouse <> regs.DX)) then
- begin
- lastmouse.xmouse := regs.CX;
- lastmouse.ymouse := regs.DX;
- questionmouse := true; {This returns true if a button has been pressed}
- end {or the mouse has been moved}
- else
- questionmouse := false;
- end;
-
- procedure mousemoved(var movement : mousemove);
- var
- check : mousemove;
- regs : registers;
- begin
- regs.AX := $000B; {Read mouse motion counters}
- intr($33, regs);
- if ((regs.CX and $8000) = $8000) then
- check.xmouse := -(not(regs.CX)) {Since the registers are unsigned }
- else {integers this check for negative }
- check.xmouse := regs.CX; {movement. Positive numbers are }
- if ((regs.DX and $8000) = $8000) then {DOWN and RIGHT, negative numbers}
- check.ymouse := -(not(regs.DX)) {are UP and LEFT}
- else
- check.ymouse := regs.DX;
- movement := check;
- end;
-
- end.