mouse_event Function

Declare Sub mouse_event Lib "user32.dll" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long)

Platforms

Description & Usage

mouse_event synthesizes mouse input by placing mouse input information into the input stream. A single mouse input event consists of either a move of the mouse or the change of the button state. For mouse movement, the coordinates can be given in either absolute or relative form. Only changes in mouse position or button state should be send via this function. For example, if the left mouse button is already down, the program should not send another left-button-down input.

Return Value

mouse_event does not return a value.

Visual Basic-Specific Issues

None.

Parameters

dwFlags
A combination of the following flags specifying which mouse input information to place into the input stream. Remember to only specify button status information for those which have changed. Note that scroll wheel movement and X button status cannot be simultaneously specified because they both use the dwData parameter.
MOUSEEVENTF_ABSOLUTE
The dx and dy parameters contain absolute mouse coordinates. In the coordinate system used by the function, the screen's upper-left corner has coordinates (0,0) and the lower-right corner has coordinates (65535,65535), regardless of the actual screen size. If this flag is not set, dx and dy contain relative coordinates, whose actual amount of movement depends on the current mouse speed and acceleration settings.
MOUSEEVENTF_LEFTDOWN
The left button was pressed.
MOUSEEVENTF_LEFTUP
The left button was released.
MOUSEEVENTF_MIDDLEDOWN
The middle button was pressed.
MOUSEEVENTF_MIDDLEUP
The middle button was released.
MOUSEEVENTF_MOVE
The mouse moved. The dx and dy parameters specify the amount or location of the movement.
MOUSEEVENTF_RIGHTDOWN
The right button was pressed.
MOUSEEVENTF_RIGHTUP
The right button was released.
MOUSEEVENTF_WHEEL
Windows NT, 2000: The scroll wheel has moved. The dwData parameter specifies the amount of movement.
MOUSEEVENTF_XDOWN
Windows 2000: An X button was pressed. The dwData parameter identifies which X buttons.
MOUSEEVENTF_XUP
Windows 2000: An X button was released. The dwData parameter identifies which X buttons.
dx
Specifies either the x-coordinate of absolute mouse movement or the amount of relative movement along the x-axis. For relative motion, positive values move right and negative values move left.
dy
Specifies either the y-coordinate of absolute mouse movement or the amount of relative movement along the y-axis. For relative motion, positive values move down and negative values move up.
dwData
Windows NT, 2000: If dwFlags contains MOUSEEVENTF_WHEEL, this specifies the amount of wheel movement, in integer multiples of WHEEL_DATA. Positive values mean forward (away) rotation, and negative values mean backwards (toward) rotation. Windows 2000: If dwFlags contains either MOUSEEVENTF_XDOWN or MOUSEEVENTF_XUP, this is a combination of the following flags specifying which X buttons have been pressed or released:
XBUTTON1
The first X button was pressed or released.
XBUTTON2
The second X button was pressed or released.
dwExtraInfo
An additional 32-bit value associated with the mouse event.

Constant Definitions

Const MOUSEEVENTF_ABSOLUTE = &H8000
Const MOUSEEVENTF_LEFTDOWN = &H2
Const MOUSEEVENTF_LEFTUP = &H4
Const MOUSEEVENTF_MIDDLEDOWN = &H20
Const MOUSEEVENTF_MIDDLEUP = &H40
Const MOUSEEVENTF_MOVE = &H1
Const MOUSEEVENTF_RIGHTDOWN = &H8
Const MOUSEEVENTF_RIGHTUP = &H10
Const MOUSEEVENTF_WHEEL = &H80
Const MOUSEEVENTF_XDOWN = &H100
Const MOUSEEVENTF_XUP = &H200
Const WHEEL_DELTA = 120
Const XBUTTON1 = &H1
Const XBUTTON2 = &H2

Example

' Simulate the mouse moving to near the lower-left corner of the
' screen and clicking (pressing and releasing) the left button.  Depending on the exact
' location of the taskbar, this will imitate clicking the Start button.

' Move the mouse to about where the Start button would be, using
' absolute coordinates.
mouse_event MOUSEEVENTF_MOVE Or MOUSEEVENTF_ABSOLUTE, 400, 65000, 0, 0
' Press and then release the left mouse button.
mouse_event MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0
mouse_event MOUSEEVENTF_LEFTUP, 0, 0, 0, 0 

Related Functions

keybd_event, SendInput

Category

Mouse

Back to the index.


Last Modified: August 7, 1999
This page is copyright © 1999 Paul Kuliniewicz. Copyright Information

Go to Paul Kuliniewicz's Home Page.
E-mail: rogue953@hotmail.com
This page is at http://skyscraper.fortunecity.com/transmission/45/api/m/mouse_event.html