MOUSEINPUT structure (Windows)

Switch View :
ScriptFree
MOUSEINPUT structure

Applies to: desktop apps only

Contains information about a simulated mouse event.

Syntax

typedef struct tagMOUSEINPUT {
  LONG      dx;
  LONG      dy;
  DWORD     mouseData;
  DWORD     dwFlags;
  DWORD     time;
  ULONG_PTR dwExtraInfo;
} MOUSEINPUT, *PMOUSEINPUT;

Members

dx

Type: LONG

The absolute position of the mouse, or the amount of motion since the last mouse event was generated, depending on the value of the dwFlags member. Absolute data is specified as the x coordinate of the mouse; relative data is specified as the number of pixels moved.

dy

Type: LONG

The absolute position of the mouse, or the amount of motion since the last mouse event was generated, depending on the value of the dwFlags member. Absolute data is specified as the y coordinate of the mouse; relative data is specified as the number of pixels moved.

mouseData

Type: DWORD

If dwFlags contains MOUSEEVENTF_WHEEL, then mouseData specifies the amount of wheel movement. A positive value indicates that the wheel was rotated forward, away from the user; a negative value indicates that the wheel was rotated backward, toward the user. One wheel click is defined as WHEEL_DELTA, which is 120.

Windows Vista: If dwFlags contains MOUSEEVENTF_HWHEEL, then dwData specifies the amount of wheel movement. A positive value indicates that the wheel was rotated to the right; a negative value indicates that the wheel was rotated to the left. One wheel click is defined as WHEEL_DELTA, which is 120.

If dwFlags does not contain MOUSEEVENTF_WHEEL, MOUSEEVENTF_XDOWN, or MOUSEEVENTF_XUP, then mouseData should be zero.

If dwFlags contains MOUSEEVENTF_XDOWN or MOUSEEVENTF_XUP, then mouseData specifies which X buttons were pressed or released. This value may be any combination of the following flags.

ValueMeaning
XBUTTON1
0x0001

Set if the first X button is pressed or released.

XBUTTON2
0x0002

Set if the second X button is pressed or released.

 

dwFlags

Type: DWORD

A set of bit flags that specify various aspects of mouse motion and button clicks. The bits in this member can be any reasonable combination of the following values.

The bit flags that specify mouse button status are set to indicate changes in status, not ongoing conditions. For example, if the left mouse button is pressed and held down, MOUSEEVENTF_LEFTDOWN is set when the left button is first pressed, but not for subsequent motions. Similarly, MOUSEEVENTF_LEFTUP is set only when the button is first released.

You cannot specify both the MOUSEEVENTF_WHEEL flag and either MOUSEEVENTF_XDOWN or MOUSEEVENTF_XUP flags simultaneously in the dwFlags parameter, because they both require use of the mouseData field.

ValueMeaning
MOUSEEVENTF_ABSOLUTE
0x8000

The dx and dy members contain normalized absolute coordinates. If the flag is not set, dxand dy contain relative data (the change in position since the last reported position). This flag can be set, or not set, regardless of what kind of mouse or other pointing device, if any, is connected to the system. For further information about relative mouse motion, see the following Remarks section.

MOUSEEVENTF_HWHEEL
0x01000

The wheel was moved horizontally, if the mouse has a wheel. The amount of movement is specified in mouseData.

Windows XP/2000:  This value is not supported.
MOUSEEVENTF_MOVE
0x0001

Movement occurred.

MOUSEEVENTF_MOVE_NOCOALESCE
0x2000

The WM_MOUSEMOVE messages will not be coalesced. The default behavior is to coalesce WM_MOUSEMOVE messages.

Windows XP/2000:  This value is not supported.
MOUSEEVENTF_LEFTDOWN
0x0002

The left button was pressed.

MOUSEEVENTF_LEFTUP
0x0004

The left button was released.

MOUSEEVENTF_RIGHTDOWN
0x0008

The right button was pressed.

MOUSEEVENTF_RIGHTUP
0x0010

The right button was released.

MOUSEEVENTF_MIDDLEDOWN
0x0020

The middle button was pressed.

MOUSEEVENTF_MIDDLEUP
0x0040

The middle button was released.

MOUSEEVENTF_VIRTUALDESK
0x4000

Maps coordinates to the entire desktop. Must be used with MOUSEEVENTF_ABSOLUTE.

MOUSEEVENTF_WHEEL
0x0800

The wheel was moved, if the mouse has a wheel. The amount of movement is specified in mouseData.

MOUSEEVENTF_XDOWN
0x0080

An X button was pressed.

MOUSEEVENTF_XUP
0x0100

An X button was released.

 

time

Type: DWORD

The time stamp for the event, in milliseconds. If this parameter is 0, the system will provide its own time stamp.

dwExtraInfo

Type: ULONG_PTR

An additional value associated with the mouse event. An application calls GetMessageExtraInfo to obtain this extra information.

Remarks

If the mouse has moved, indicated by MOUSEEVENTF_MOVE, dxand dy specify information about that movement. The information is specified as absolute or relative integer values.

If MOUSEEVENTF_ABSOLUTE value is specified, dx and dy contain normalized absolute coordinates between 0 and 65,535. The event procedure maps these coordinates onto the display surface. Coordinate (0,0) maps onto the upper-left corner of the display surface; coordinate (65535,65535) maps onto the lower-right corner. In a multimonitor system, the coordinates map to the primary monitor.

If MOUSEEVENTF_VIRTUALDESK is specified, the coordinates map to the entire virtual desktop.

If the MOUSEEVENTF_ABSOLUTE value is not specified, dxand dy specify movement relative to the previous mouse event (the last reported position). Positive values mean the mouse moved right (or down); negative values mean the mouse moved left (or up).

Relative mouse motion is subject to the effects of the mouse speed and the two-mouse threshold values. A user sets these three values with the Pointer Speed slider of the Control Panel's Mouse Properties sheet. You can obtain and set these values using the SystemParametersInfo function.

The system applies two tests to the specified relative mouse movement. If the specified distance along either the x or y axis is greater than the first mouse threshold value, and the mouse speed is not zero, the system doubles the distance. If the specified distance along either the x or y axis is greater than the second mouse threshold value, and the mouse speed is equal to two, the system doubles the distance that resulted from applying the first threshold test. It is thus possible for the system to multiply specified relative mouse movement along the x or y axis by up to four times.

Requirements

Minimum supported client

Windows 2000 Professional

Minimum supported server

Windows 2000 Server

Header

Winuser.h (include Windows.h)

See also

Reference
GetMessageExtraInfo
INPUT
SendInput
Conceptual
Keyboard Input

 

 

Send comments about this topic to Microsoft

Build date: 3/6/2012

Community Content

TheToid
Multi Monitor environment with MOUSEEVENTF_ABSOLUTE
It should also be noted, that when using MOUSEEVENTF_ABSOLUTE in a multi monitor environment, the values 0 - 65535 are positions for the primary monitor only, values outside this range translate to the other monitors, the correct formula to convert VirtualScreen (Entire Desktop) coorindates to the MOUSEEVENTF_ABSOLUTE coordinates is: X = (VirtualScreenX - PrimaryScreen.Left) * 65535 / PrimaryScreen.Width Y = (VirtualScreenY - PrimaryScreen.Top) * 65535 / PrimaryScreen.Height This will work with multi monitors if you use this formula.

A46ED07E-3459-4713-89FC-1206DD10FB40
Move, then click
As far as I can see, if one wants to click at the particular position, the move event must be sent first. Coordinates provided with button message don't seem to take any effect.

Rajnish Chauhan
set dwFlags = MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_MOVE to set absoulte co-ordinates
If you want to send mouse cursor to some absolute location then you have to set MOUSEEVENTF_MOVE along with MOUSEEVENTF_ABSOLUTE flag

Inputs.type = INPUT_MOUSE ;
Inputs.mi.dx = i;
Inputs.mi.dy = 0x00;
Inputs.mi.mouseData = 0;
Inputs.mi.dwFlags = MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_MOVE ;

MikeDixon
Rounding with MOUSEEVENTF_ABSOLUTE
From extensively testing this, the specific function that is being used to convert back from normalized coordinates to pixels is equivalent to:
x = trunc(dx*ScreenWidth/65536)
y = trunc(dy*ScreenHeight/65536)

So to make sure that the click arrives at the exact coordinates you desire, you have to convert from pixels to normalized like this:
dx = ceiling(x*65536/ScreenWidth)
dy = ceiling(y*65536/ScreenHeight)

In a multi-monitor setup, ScreenWidth and ScreenHeight are the width and height of the primary monitor.

Caveats: I have only tested this for positive values of x and y, and only on Windows XP SP3.

win32 sucks
dx and dy are not pixels when using MOUSEEVENTF_ABSOLUTE
It's not obvious unless you read this entire page, but dx and dy are not pixel values when using MOUSEEVENTF_ABSOLUTE. To convert from pixels, do something like this:

dx = x * (65335/ScreenWidth)
dy = y * (65335/ScreenHeight)

This isn't mentioned in the description of dx, dy, or MOUSEEVENTF_ABSOLUTE.