Mouse event handling unit The Mouse unit implements a platform independent mouse handling interface. It is implemented identically on all platforms supported by Free Pascal and can be enhanced with custom drivers, should this be needed. It is intended to be used only in text-based screens, for instance in conjunction with the keyboard and video unit. No support for graphical screens is implemented, and there are (currently) no plans to implement this. Base for mouse error codes. Mouse initialization error Mouse driver not implemented. Mouse button down event signal. Mouse button up event signal. Mouse cursor move event signal. Left mouse button event. Right mouse button event. Middle mouse button event. 4th mouse button event 5th mouse button event Mouse event buffer size The mouse unit has a mechanism to buffer mouse events. This constant defines the size of the event buffer. Pointer to record. Mouse event reporting record.

The TMouseEvent is the central type of the mouse unit, it is used to describe all mouse events.

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 constants defined in the unit interface.

Horizontal position of mouse cursor. Vertical position of mouse cursor. Pressed buttons at time of event. Type of event. Mouse driver structure The TMouseDriver record is used to implement a mouse driver in the function. Its fields must be filled in before calling the function. Should the default event queue mechanism be used. Called when the driver must be initialized Called when the driver will be unloaded. Function called when the mouse must be detected. Function called when the mouse cursor must be shown. Function called when the mouse cursor must be hidden. Called to get the mouse cursors horizontal position. Called to get the mouse cursors vertical position. Called to get the currently pressed mouse buttons. Called when the current mouse position must be set. Called to get the next mouse event. Waits if needed. Called to get the next mouse event. Does not wait. Called to put a mouse event back in the queue. Internal mouse flag This variable keeps track of the last known internal mouse state. Do not use. Mouse button state This variable keeps track of the last known mouse button state. Do not use. Mouse cursor horizontal position This variable keeps track of the last known cursor position. Do not use. Mouse cursor vertical position This variable keeps track of the last known cursor position. Do not use. Detect the presence of a mouse.

DetectMouse detects whether a mouse is attached to the system or not. If there is no mouse, then zero is returned. If a mouse is attached, then the number of mouse buttons is returnead.

This function should be called after the mouse driver was initialized.

None. ,
Deinitialize mouse driver.

DoneMouse De-initializes the mouse driver. It cleans up any memory allocated when the mouse was initialized, or removes possible mouse hooks from memory. The mouse functions will not work after DoneMouse was called. If DoneMouse is called a second time, it will exit at once. InitMouse should be called before DoneMouse can be called again.

For an example, see most other mouse functions.

None.
Get the state of the mouse buttons

GetMouseButtons returns the current button state of the mouse, i.e. it returns a or-ed combination of the following constants:

MouseLeftButton
When the left mouse button is held down.
MouseRightButton
When the right mouse button is held down.
MouseMiddleButton
When the middle mouse button is held down.
None.
Get a copy of the currently active mouse driver.

GetMouseDriver returns the currently set mouse driver. It can be used to retrieve the current mouse driver, and override certain callbacks.

A more detailed explanation about getting and setting mouse drivers can be found in .

For an example, see the section on writing a custom mouse driver,

None.
Get next mouse event from the queue.

GetMouseEvent returns the next mouse event (a movement, button press or button release), and waits for one if none is available in the queue.

Some mouse drivers can implement a mouse event queue which can hold multiple events till they are fetched. Others don't, and in that case, a one-event queue is implemented for use with .

None.
Query the current horizontal position of the mouse cursor. GetMouseX returns the current X position of the mouse. X is measured in characters, starting at 0 for the left side of the screen. None. Query the current vertical position of the mouse cursor.

GetMouseY returns the current Y position of the mouse. Y is measured in characters, starting at 0 for the top of the screen.

For an example, see

None.
Hide the mouse cursor. HideMouse hides the mouse cursor. This may or may not be implemented on all systems, and depends on the driver. None. Initialize the FPC mouse driver.

InitMouse Initializes the mouse driver. This will allocate any data structures needed for the mouse to function. All mouse functions can be used after a call to InitMouse.

A call to InitMouse must always be followed by a call to at program exit. Failing to do so may leave the mouse in an unusable state, or may result in memory leaks.

For an example, see most other functions.

None.
Query next mouse event. Do not wait if none available.

PollMouseEvent checks whether a mouse event is available, and returns it in MouseEvent if one is found. The function result is True in that case. If no mouse event is pending, the function result is False, and the contents of MouseEvent is undefined.

Note that after a call to PollMouseEvent, the event should still be removed from the mouse event queue with a call to GetMouseEvent.

None.
Put a mouse event in the venet queue.

PutMouseEvent adds MouseEvent to the input queue. The next call to or PollMouseEvent will then return MouseEvent.

Please note that depending on the implementation the mouse event queue can hold only one value.

None.
Set a new mouse driver.

SetMouseDriver sets the mouse driver to Driver. This function should be called before is called, or after DoneMouse is called. If it is called after the mouse has been initialized, it does nothing.

For more information on setting the mouse driver, .

For an example, see

Set the mouse cursor position. SetMouseXY places the mouse cursor on X,Y. X and Y are zero based character coordinates: 0,0 is the top-left corner of the screen, and the position is in character cells (i.e. not in pixels). None. Show the mouse cursor.

ShowMouse shows the mouse cursor if it was previously hidden. The capability to hide or show the mouse cursor depends on the driver.

For an example, see

None.
Writing a custom mouse driver

The mouse unit has support for adding a custom mouse driver. This can be used to add support for mouses not supported by the standard Free Pascal driver, but also to enhance an existing driver for instance to log mouse events or to implement a record and playback function.

The following unit shows how a mouse driver can be enhanced by adding some logging capabilities to the driver.