Board index » delphi » HELP! mouse driver for TP

HELP! mouse driver for TP

Where can I find a mouse driver, or code, so I can use a mouse for input
to a program I am writing in Turbo Pascal.  Thanks   -Bob

 

Re:HELP! mouse driver for TP


In message <3277CDD3.1...@iland.net> - Bob Cushing <bcush...@iland.net>Wed, 30
Oct 1996 15:51:15 -0600 writes:

:>
:>Where can I find a mouse driver, or code, so I can use a mouse for input
:>to a program I am writing in Turbo Pascal.  Thanks   -Bob

Here is a Unit I've used in the past.  It's not a FULL interface, but it has
enough to do some basic stuff.

unit MOUSE ;

{$O+,F+}

interface

uses dos ;

const
  MOUSE_INSTALLED : boolean = false ;
  MOUSE_VERSION   : word = 0 ;
  MOUSE_BUTTONS   : word = 0 ;
  MOUSE_TYPE      : word = 0 ;
  MOUSE_IRQ       : word = 0 ;

procedure MOUSE_SHOW_POINTER ;
procedure MOUSE_HIDE_POINTER ;
procedure MOUSE_POSITION_STATUS (var LEFT,RIGHT,CENTER: boolean; var X,Y:
word) ;
procedure MOUSE_SET_POSITION (X,Y: word) ;
procedure MOUSE_BUTTON_PRESS (BUTTON: word; var LEFT,RIGHT,CENTER: boolean;
var CNT,X,Y: word) ;
procedure MOUSE_BUTTON_RELEASE (BUTTON: word; var LEFT,RIGHT,CENTER: boolean;
var CNT,X,Y: word) ;
procedure MOUSE_SET_HORZ_LIMITS(MIN,MAX: word) ;
procedure MOUSE_SET_VERT_LIMITS(MIN,MAX: word) ;
procedure MOUSE_TEXT_POINTER(TYP,AMASK,OMASK: word) ;

implementation

var
  REG : registers ;

procedure MOUSE_SHOW_POINTER ;
assembler ;

{  Displays the mouse pointer, and cancels any mouse pointer exclusion    }
{  area previously defined with mouse function $10.                       }

{  A counter is maintained; it is decremented by calls to Mouse function  }
{  $02 and incremented (if non-zero) with this function.  When the        }
{  counter is 0 or becomes 0, the mouse pointer is displayed.  When the   }
{  mouse driver is reset with mouse function $00, the counter is forced   }
{  to -1.                                                                 }

asm
  mov   ax, 0001h
  int   33h
end ;

procedure MOUSE_HIDE_POINTER ;
assembler ;

{  Removes the mouse pointer from the display.  The driver continues to   }
{  track the mouse position.                                              }

{  See Mouse function $01 for note about counter.                         }

asm
  mov   ax, 0002h
  int   33h
end ;

procedure MOUSE_POSITION_STATUS ;

{  Returns the current mouse button status and pointer position           }

{  Coordinates are returned in pixels, regardless of the current display  }
{  mode.  Position (x,y)=(0,0) is the upper left corner of the screen.    }

begin
  LEFT := false ;
  RIGHT := false ;
  CENTER := false ;

  REG.AX := $0003 ;
  intr($33,REG) ;

  X := REG.CX ;
  Y := REG.DX ;
  LEFT := (REG.BX and 1) = 1 ;
  RIGHT := (REG.BX and 2) = 2 ;
  CENTER := (REG.BX and 4) = 4 ;
end ;

procedure MOUSE_SET_POSITION ;
assembler ;

{  Sets the position of the mouse pointer.  The pointer is displayed at   }
{  the new position unless it has been hiden with Mouse function $02 or   }
{  unless the new position lies within an exclusion area defined with     }
{  Mouse function $10.                                                    }

{  Coordinates are specified in pixels, regardless of the current display }
{  mode.  Position (x,y)=(0,0) is the upper left corner of the screen.    }

{  The position is adjusted (if necessary) to lie within the horizontal   }
{  and vertical limits specified with a previous call to mouse functions  }
{  $07 and $08.                                                           }

asm
  mov   ax, 0004h
  mov   cx, X
  mov   dx, Y
  int   33h
end ;

procedure MOUSE_BUTTON_PRESS ;

{  Returns the current status of all mouse buttons and the number or      }
{  presses and  the position of the last press for a specified mouse      }
{  button since the last call to this function for that button.  The      }
{  press counter for the button is reset to 0.                            }

begin
  REG.AX := $0005 ;
  REG.BX := BUTTON ;
  intr($33,REG) ;
  X := REG.CX ;
  Y := REG.DX ;
  CNT := REG.BX ;
  LEFT := (REG.AX and 1) = 1 ;
  RIGHT := (REG.AX and 2) = 2 ;
  CENTER := (REG.AX and 4) = 4 ;
end ;

procedure MOUSE_BUTTON_RELEASE ;

{  Returns the current status of all mouse buttons and the number of      }
{  releases and the position of the last release for a specified mouse    }
{  button since the last call to this function for that button.  The      }
{  release counter for the button is reset to 0.                          }

begin
  REG.AX := $0006 ;
  REG.BX := BUTTON ;
  intr($33,REG) ;
  X := REG.CX ;
  Y := REG.DX ;
  CNT := REG.BX ;
  LEFT := (REG.AX and 1) = 1 ;
  RIGHT := (REG.AX and 2) = 2 ;
  CENTER := (REG.AX and 4) = 4 ;
end ;

procedure MOUSE_SET_HORZ_LIMITS ;
assembler ;

{  Limits the mouse pointer display area by assigning minimum and maximum }
{  horizontal (x) coordinates for the mouse pointer.                      }

{  If the minimum value is greater than the maximum value, the two values }
{  are swapped.                                                           }

{  The mouse pointer will be moved (if necessary) so that it lies within  }
{  the specified horizontal coordinates.                                  }

{  See also mouse function $10, which defines an exclusion area for the   }
{  mouse pointer.                                                         }

asm
  mov   ax, 0007h
  mov   cx, MIN
  mov   dx, MAX
  int   33h
end ;

procedure MOUSE_SET_VERT_LIMITS ;
assembler ;

{  Limits the mouse pointer display area by assigning minimum and maximum }
{  vertical (x) coordinates for the mouse pointer.                        }

{  If the minimum value is greater than the maximum value, the two values }
{  are swapped.                                                           }

{  The mouse pointer will be moved (if necessary) so that it lies within  }
{  the specified vertical coordinates.                                    }

{  See also mouse function $10, which defines an exclusion area for the   }
{  mouse pointer.                                                         }

asm
  mov   ax, 0008h
  mov   cx, MIN
  mov   dx, MAX
  int   33h
end ;

procedure MOUSE_TEXT_POINTER ;
assembler ;

asm
  mov   ax, 000ah
  mov   bx, TYP
  mov   cx, AMASK
  mov   dx, OMASK
  int   33h
end ;

begin
  REG.AX := $00 ;
  intr($33,REG) ;
  MOUSE_INSTALLED := (REG.AX = $ffff) ;

  if MOUSE_INSTALLED then begin
    REG.AX := $0024 ;
    intr($33,REG) ;
    MOUSE_VERSION := REG.BX ;
    MOUSE_TYPE := REG.CH ;
    MOUSE_IRQ := REG.CL ;
  end ;
end .

Other Threads