提供一些MSDN资料。<br>其中我测试过模拟鼠标移动,是确实可行的。但没有测试模拟键盘按键,你不妨试一下。<br><br><br>移动鼠标光标可以考虑API函数SetCursorPos<br>先说几个API函数<br>keybd_event<br>The keybd_event function synthesizes a keystroke. The system can use such a synthesized keystroke to generate a WM_KEYUP or WM_KEYDOWN message. The keyboard driver's interrupt handler calls the keybd_event function. <br><br>Windows NT: This function has been superseded. Use SendInput instead.<br><br>VOID keybd_event(<br> BYTE bVk, // virtual-key code<br> BYTE bScan, // hardware scan code<br> DWORD dwFlags, // flags specifying various function options<br> DWORD dwExtraInfo // additional data associated with keystroke<br>);<br> <br>Parameters<br>bVk <br>Specifies a virtual-key code. The code must be a value in the range 1 to 254. <br>bScan <br>Specifies a hardware scan code for the key. <br>dwFlags <br>A set of flag bits that specify various aspects of function operation. An application can use any combination of the following predefined constant values to set the flags. Value Meaning <br>KEYEVENTF_EXTENDEDKEY If specified, the scan code was preceded by a prefix byte having the value 0xE0 (224). <br>KEYEVENTF_KEYUP If specified, the key is being released. If not specified, the key is being depressed. <br><br><br>dwExtraInfo <br>Specifies an additional 32-bit value associated with the key stroke. <br>Return Values<br>This function has no return value. <br><br>Remarks<br>Although keybd_event passes an OEM-dependent hardware scan code to the system, applications should not use the scan code. The system converts scan codes to virtual-key codes internally and clears the up/down bit in the scan code before passing it to applications. <br><br>An application can simulate a press of the PRINTSCREEN key in order to obtain a screen snapshot and save it to the clipboard. To do this, call keybd_event with the bVk parameter set to VK_SNAPSHOT, and the bScan parameter set to 0 for a snapshot of the full screen or set bScan to 1 for a snapshot of the active window. <br><br>Windows CE: Windows CE supports an additional flag for the dwFlags parameter. Use the KEYEVENTF_SILENT flag to simulate a keystroke without making a clicking sound.<br><br>Windows CE does not support the KEYEVENTF_EXTENDEDKEY flag.<br><br>QuickInfo<br> Windows NT: Requires version 3.1 or later.<br> Windows: Requires Windows 95 or later.<br> Windows CE: Requires version 1.0 or later.<br> Header: Declared in winuser.h.<br> Import Library: Use user32.lib.<br><br>See Also<br>Keyboard Input Overview, Keyboard Input Functions, GetAsyncKeyState, GetKeyState, MapVirtualKey, SetKeyboardState <br><br><br>mouse_event<br>The mouse_event function synthesizes mouse motion and button clicks. <br><br>Windows NT: This function has been superseded. Use SendInput instead.<br><br>VOID mouse_event(<br> DWORD dwFlags, // flags specifying various motion/click variants<br> DWORD dx, // horizontal mouse position or position change<br> DWORD dy, // vertical mouse position or position change<br> DWORD dwData, // amount of wheel movement<br> DWORD dwExtraInfo <br> // 32 bits of application-defined information<br>);<br> <br>Parameters<br>dwFlags <br>A set of flag bits that specify various aspects of mouse motion and button clicking. The bits in this parameter can be any reasonable combination of the following values: Value Meaning <br>MOUSEEVENTF_ABSOLUTE Specifies that the dx and dy parameters contain normalized absolute coordinates. If not set, those parameters 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 mouse-like device, if any, is connected to the system. For further information about relative mouse motion, see the following Remarks section. <br>MOUSEEVENTF_MOVE Specifies that movement occurred. <br>MOUSEEVENTF_LEFTDOWN Specifies that the left button is down. <br>MOUSEEVENTF_LEFTUP Specifies that the left button is up. <br>MOUSEEVENTF_RIGHTDOWN Specifies that the right button is down. <br>MOUSEEVENTF_RIGHTUP Specifies that the right button is up. <br>MOUSEEVENTF_MIDDLEDOWN Specifies that the middle button is down. <br>MOUSEEVENTF_MIDDLEUP Specifies that the middle button is up. <br>MOUSEEVENTF_WHEEL Windows NT: Specifies that the wheel has been moved, if the mouse has a wheel. The amount of movement is given in dwData <br><br><br>dx <br>Specifies the mouse's absolute position along the x-axis or its amount of motion since the last mouse event was generated, depending on the setting of MOUSEEVENTF_ABSOLUTE. Absolute data is given as the mouse's actual x-coordinate; relative data is given as the number of mickeys moved. A mickey is the amount that a mouse has to move for it to report that it has moved. <br>dy <br>Specifies the mouse's absolute position along the y-axis or its amount of motion since the last mouse event was generated, depending on the setting of MOUSEEVENTF_ABSOLUTE. Absolute data is given as the mouse's actual y-coordinate; relative data is given as the number of mickeys moved. <br>dwData <br>If dwFlags is MOUSEEVENTF_WHEEL, then dwData 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. <br>If dwFlags is not MOUSEEVENTF_WHEEL, then dwData should be zero. <br><br>dwExtraInfo <br>Specifies an additional 32-bit value associated with the mouse event. An application calls GetMessageExtraInfo to obtain this extra information. <br>Return Values<br>This function has no return value. <br><br>Remarks<br>If the mouse has moved, indicated by MOUSEEVENTF_MOVE being set, dx and dy hold information about that motion. The information is given as absolute or relative integer values. <br><br>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, (65535,65535) maps onto the lower-right corner. <br><br>If the MOUSEEVENTF_ABSOLUTE value is not specified, dx and dy specify relative motions from when the last mouse event was generated (the last reported position). Positive values mean the mouse moved right (or down); negative values mean the mouse moved left (or up). <br><br>Relative mouse motion is subject to the settings for mouse speed and acceleration level. An end user sets these values using the Mouse control panel application. An application obtains and sets these values with theSystemParametersInfo function. <br><br>The system applies two tests to the specified relative mouse motion when applying acceleration. If the specified distance along either the x or y axis is greater than the first mouse threshold value, and the mouse acceleration level is not zero, the operating 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 acceleration level is equal to two, the operating system doubles the distance that resulted from applying the first threshold test. It is thus possible for the operating system to multiply relatively-specified mouse motion along the x or y axis by up to four times.<br><br>Once acceleration has been applied, the system scales the resultant value by the desired mouse speed. Mouse speed can range from 1 (slowest) to 20 (fastest) and represents how much the pointer moves based on the distance the mouse moves. The default value is 10, which results in no additional modification to the mouse motion. <br><br>The mouse_event function is used to synthesize mouse events by applications that need to do so. It is also used by applications that need to obtain more information from the mouse than its position and button state. For example, if a tablet manufacturer wants to pass pen-based information to its own applications, it can write a dynamic-link library (DLL) that communicates directly to the tablet hardware, obtains the extra information, and saves it in a queue. The DLL then calls mouse_event with the standard button and x/y position data, along with, in the dwExtraInfo parameter, some pointer or index to the queued extra information. When the application needs the extra information, it calls the DLL with the pointer or index stored in dwExtraInfo, and the DLL returns the extra information. <br><br>Windows CE: Windows CE does not support the MOUSEEVENTF_WHEEL constant in the dwFlags parameter.<br><br>QuickInfo<br> Windows NT: Requires version 3.1 or later.<br> Windows: Requires Windows 95 or later.<br> Windows CE: Unsupported.<br> Header: Declared in winuser.h.<br> Import Library: Use user32.lib.<br><br>See Also<br>Mouse Input Overview, Mouse Input Functions, GetMessageExtraInfo,SystemParametersInfo<br><br> -摘自MSDN<br>Keyboard input 及 Mouse Input部分<br> <br>