15.1 Constants, Types and Variables

Constants

The following constants can be used when mouse drivers need to report errors:
 const
   { We have an errorcode base of 1030 }
   errMouseBase                    = 1030;
   errMouseInitError               = errMouseBase + 0;
   errMouseNotImplemented          = errMouseBase + 1;
The following constants describe which action a mouse event describes
 const
   MouseActionDown = $0001;  { Mouse down event }
   MouseActionUp   = $0002;  { Mouse up event }
   MouseActionMove = $0004;  { Mouse move event }
The following constants describe the used buttons in a mouse event:
   MouseLeftButton   = $01;  { Left mouse button }
   MouseRightButton  = $02;  { Right mouse button }
   MouseMiddleButton = $04;  { Middle mouse button }
The mouse unit has a mechanism to buffer mouse events. The following constant defines the size of the event buffer:
 MouseEventBufSize = 16;

Types

The TMouseEvent is the central type of the mouse unit, it is used to describe the mouse events:
 PMouseEvent=^TMouseEvent;
 TMouseEvent=packed record { 8 bytes }
   buttons : word;
   x,y     : word;
   Action  : word;
 end;
The Buttons field describes which buttons were down when the event occurred. The x,y fields describe where the event occurred on the screen. The Action describes what action was going on when the event occurred. The Buttons and Action field can be examined using the above constants.

The following record is used to implement a mouse driver in the SetMouseDriver (510) function:

 TMouseDriver = Record
   UseDefaultQueue : Boolean;
   InitDriver : Procedure;
   DoneDriver : Procedure;
   DetectMouse : Function : Byte;
   ShowMouse : Procedure;
   HideMouse : Procedure;
   GetMouseX : Function : Word;
   GetMouseY : Function : Word;
   GetMouseButtons : Function : Word;
   SetMouseXY : procedure (x,y:word);
   GetMouseEvent : procedure (var MouseEvent:TMouseEvent);
   PollMouseEvent : function (var MouseEvent: TMouseEvent):boolean;
   PutMouseEvent : procedure (Const MouseEvent:TMouseEvent);
 end;
Its fields will be explained in the section on writing a custom driver.

Variables

The following variables are used to keep the current position and state of the mouse.
 MouseIntFlag : Byte;  { Mouse in int flag }
 MouseButtons : Byte;  { Mouse button state }
 MouseWhereX,
 MouseWhereY  : Word;  { Mouse position }