函数 SendInput,模拟 按键,鼠标动作,鼠标点击事件.
语法:UINT SendInput(UINT nInputs,
LPINPUT pInputs,
int cbSize
);
参数:
nInputs
[in] 指定连续模拟事件个数[即(pInputs)INPUT结构数组个数].
pInputs
[in] INPUT结构指针(数组),每个结构描叙一个模拟事件.
cbSize
[in] 指定结构数组的字节大小.
Return Value
函数返回成功模拟的事件数目. 如果返回0表示,事件被其它线程中断.
INPUT input[6];
::ZeroMemory(input, sizeof(input));
input[0].type = INPUT_KEYBOARD;
input[1].type = INPUT_KEYBOARD;
input[2].type = INPUT_KEYBOARD;
input[3].type = INPUT_KEYBOARD;
input[4].type = INPUT_KEYBOARD;
input[0].ki.wVk = VK_CONTROL;
input[1].ki.wVk = 'V';
input[2].ki.wVk = 'V';
input[2].ki.dwFlags = KEYEVENTF_KEYUP;
input[3].ki.wVk = VK_CONTROL;
input[3].ki.dwFlags = KEYEVENTF_KEYUP;
input[4].ki.wVk = VK_RETURN;
input[5].ki.wVk = VK_RETURN;
input[5].ki.dwFlags = KEYEVENTF_KEYUP;
::SendInput(6, &input[0], sizeof(INPUT));
这一段模拟了,按按Crtl+V 然后再按回车
typedef struct tagINPUT {
DWORD type;
union {MOUSEINPUT mi;
KEYBOARDINPUT 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.
Remarks
This structure contains information identical to that used in the parameter list of the keybd_event or mouse_event function.
typedef struct tagKEYBDINPUT {
WORD wVk;
WORD wScan;
DWORD dwFlags;
DWORD time;
ULONG_PTR dwExtraInfo;
} KEYBDINPUT, *PKEYBDINPUT;
Members
wVk
Specifies a virtual-key code. The code must be a value in the range 1 to 254. The Winuser.h header file provides macro definitions (VK_*) for each value. If the dwFlags member specifies KEYEVENTF_UNICODE, wVk must be 0.
wScan
Specifies a hardware scan code for the key. If dwFlags specifies KEYEVENTF_UNICODE, wScan specifies a Unicode character which is to be sent to the foreground application.
dwFlags
Specifies various aspects of a keystroke. This member can be certain combinations of the following values.
KEYEVENTF_EXTENDEDKEY
If specified, the scan code was preceded by a prefix byte that has the value 0xE0 (224).
KEYEVENTF_KEYUP
If specified, the key is being released. If not specified, the key is being pressed.
KEYEVENTF_SCANCODE
If specified, wScan identifies the key and wVk is ignored.
KEYEVENTF_UNICODE
Windows 2000/XP: If specified, the system synthesizes a VK_PACKET keystroke. The wVk parameter must be zero. This flag can only be combined with the KEYEVENTF_KEYUP flag. For more information, see the Remarks section.
time
Time stamp for the event, in milliseconds. If this parameter is zero, the system will provide its own time stamp.
dwExtraInfo
Specifies an additional value associated with the keystroke. Use the GetMessageExtraInfo function to obtain this information.
Remarks
Windows 2000/XP: INPUT_KEYBOARD supports nonkeyboard-input methods—such as handwriting recognition or voice recognition—as if it were text input by using the KEYEVENTF_UNICODE flag. If KEYEVENTF_UNICODE is specified, SendInput sends a WM_KEYDOWN or WM_KEYUP message to the foreground thread's message queue with wParam equal to VK_PACKET. Once GetMessage or PeekMessage obtains this message, passing the message to TranslateMessage posts a WM_CHAR message with the Unicode character originally specified by wScan. This Unicode character will automatically be converted to the appropriate ANSI value if it is posted to an ANSI window.
Windows 2000/XP: Set the KEYEVENTF_SCANCODE flag to define keyboard input in terms of the scan code. This is useful to simulate a physical keystroke regardless of which keyboard is currently being used. The virtual key value of a key may alter depending on the current keyboard layout or what other keys were pressed, but the scan code will always be the same.
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.
Windows 2000/XP: IfdwFlags 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.
XBUTTON1
Set if the first X button is pressed or released.
XBUTTON2
Set if the second X button is pressed or released.
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_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.
MOUSEEVENTF_VIRTUALDESK
Windows 2000/XP:Maps coordinates to the entire desktop. Must be used with MOUSEEVENTF_ABSOLUTE.
MOUSEEVENTF_WHEEL
Windows NT/2000/XP: Specifies that the wheel was moved, if the mouse has a wheel. The amount of movement is specified in mouseData .
MOUSEEVENTF_XDOWN
Windows 2000/XP: Specifies that an X button was pressed.
MOUSEEVENTF_XUP
Windows 2000/XP: Specifies that an X 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.
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.
Windows 2000/XP: 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.
Structure Information
GetActiveWindow函数GetForegroundWindow | _beginthread还是createThread |
键盘模拟 | |
[ 发布日期:20年前 (2004-11-15) ] [ 来自:Original ] | [分类:C\C++相关] |
[ 分类:C\C++相关
| 查看:1045 ]
暂时没有评论,快来发表一个评论吧。
发表评论 |