来自MSDN
SendInput Function
The SendInput function synthesizes keystrokes, mouse motions, and button clicks
UINT SendInput(UINT nInputs,
LPINPUT pInputs,
int cbSize);
Parameters
nInputs
[in] Number of structures in the pInputs array.
pInputs
[in] Pointer to an array of INPUT structures. Each structure represents an event to be inserted into the keyboard or mouse input stream.
cbSize
[in] Specifies the size, in bytes, of an INPUT structure. If cbSize is not the size of an INPUT structure, the function fails
Return Value
The function returns the number of events that it successfully inserted into the keyboard or mouse input stream. If the function returns zero, the input was already blocked by another thread. To get extended error information, call GetLastError.
INPUT Structure
The INPUT structure is used by SendInput to store information for synthesizing input events such as keystrokes, mouse movement, and mouse clicks.
typedef struct tagINPUT {
DWORD type;
union {MOUSEINPUT mi;
KEYBDINPUT ki;
HARDWAREINPUT hi;
};
}INPUT, *PINPUT;
Members
type
Specifies the type of the input event. This member can be one of the following values.
INPUT_MOUSE
The event is a mouse event. Use the mi structure of the union.
INPUT_KEYBOARD
The event is a keyboard event. Use the ki structure of the union.
INPUT_HARDWARE
Windows 95/98/Me: The event is from input hardware other than a keyboard or mouse. Use the hi structure of the union.
mi
A MOUSEINPUT structure that contains information about a simulated mouse event.
ki
A KEYBDINPUT structure that contains information about a simulated keyboard event.
hi
Windows 95/98/Me: A HARDWAREINPUT structure that contains information about a simulated event from input hardware other than a keyboard or mouse.
MOUSEINPUT Structure
The MOUSEINPUT structure contains information about a simulated mouse event.
typedef struct tagMOUSEINPUT {
LONG dx;
LONG dy;
DWORD mouseData;
DWORD dwFlags;
DWORD time;
ULONG_PTR dwExtraInfo;
} MOUSEINPUT, *PMOUSEINPUT;
Members
dx
Specifies 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
Specifies 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
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.
dwFlags
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.
MOUSEEVENTF_ABSOLUTE
Specifies that 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_MOVE
Specifies that movement occurred.
MOUSEEVENTF_MOVE_NOCOALESCE
Windows Vista: Specifies that WM_MOUSEMOVE messages will not be coalesced. The default behavior is to coalesce WM_MOUSEMOVE messages.
MOUSEEVENTF_LEFTDOWN
Specifies that the left button was pressed.
MOUSEEVENTF_LEFTUP
Specifies that the left button was released.
MOUSEEVENTF_RIGHTDOWN
Specifies that the right button was pressed.
MOUSEEVENTF_RIGHTUP
Specifies that the right button was released.
MOUSEEVENTF_MIDDLEDOWN
Specifies that the middle button was pressed.
MOUSEEVENTF_MIDDLEUP
Specifies that the middle button was released.
time
Time stamp for the event, in milliseconds. If this parameter is 0, the system will provide its own time stamp.
dwExtraInfo
Specifies an additional value associated with the mouse event. An application calls GetMessageExtraInfo to obtain this extra information.