Several ways to simulate the mouse keyboard under Windows
Recently, the server (the third party's ASP server, not IIS) always can't run automatically after startup, there may be bugs, you need to click the Start button to connect to the Internet. To ensure the stability of the little bit Run, I configure my machine (put home) to start once every hour, automatically run the server software after startup, this software does not have similar: / run, etc., so I think, can automatically implement analog mouse Click on the button's function? Because my needs and running environments allow me to do this: 1 "Run" button after this software is started to display location fixed 2 You can only click on the run button, there is 2 conditions, so the program The method of simulating the clicking Run button is feasible. So I use Google to investigate :-) As a programmer, there are two ways to solve such a problem: 1 Use the ready-made program 2 to do something to see .... The actual need is input on Google, the mouse simulation can find several options 1 using the "button elves" and other ready-made software (this is not in this article introduction) 2 online there is .NET implementation mouse simulation method http: // Www.cnblogs.com/edobnet/archive/2004/06/09/14334.ASPX 3 Using MFC implementation method, the most, the most famous is the article of Xu Jinghou on vckbase (see Xu Jingzhou's column) 4
Programming with MS Active Accessibility interfaces, heavyweight, high-grade, ready-made, huh, several Chinese methods are used: setCursorpos and mouse_event WinAPI is implemented. Implementation prototype: setCursorpos (xxx, xxx); mouse_event (MouseEventf_leftdown, 0, 0, 0); mouse_event (MouseEventf_leftup, 0,0,0,0); Interest readers can refer to the introduction of the above article
This article introduces another method: use: Sendinput WinApi, this method is as follows: [New for Windows NT 4.0 Service Pack 3.] The sendInput function synthesizes keyStrokes, mouse motions, and button clicks. It seems that it integrates the keyboard button, mouse Activity, handwritten board input, etc., you can implement the needs of the previously proposed. There is another structure used by Sendinput: Structure: Input [New for Windows NT 4.0 Service Pack 3.] The Input Structure Is Used by sendInput to Synthesize Keystrokes Mouse motions, and button copy; type {mouseinput mi; keybdinput ki; hardwareInput hi;};} input, * pinput, far * lpinput;
More detailed information reference: http://www.piclist.com/techref/os/win/api/Win32/struc/src/str09_12.htm http://www.china-askpro.com/msg18/qa18.shtml http://www.daniweb.com/techtalkforums/showthread.php?t=6727 The following code uses dev compiles. (2 files)
//stdafx.h#pragma overce # define win32_lean_and_mean #define _win32_winnt 0x0500 // Note that the VC generated code value is: 0x0400, pay attention to #include
INT Main (int Argc, char * argv []) {input * buffer = new input [3]; buffer-> type = input_mouse; buffer-> mi.dx = 100; buffer-> mi.dy = 100; buffer > mousedata = 0; buffer-> mi.dwflags = (mouseeventf_absolute | mouseeventf_move); buffer-> mi.time = 0; buffer-> mi.dwextrainfo = 0;
(Buffer 1) -> Type = INPUT_MOUSE; (Buffer 1) -> mi.dx = 100; (Buffer 1) -> mi.dy = 100; (buffer 1) -> mi.mousedata = 0; (Buffer 1) -> mi.dwflags = mouseeventf_leftdown; (buffer 1) -> mi.time = 0; (buffer 1) -> mi.dwextrainfo = 0;
(Buffer 2) -> Type = INPUT_MOUSE; (Buffer 2) -> mi.dx = 100; (buffer 2) -> mi.dy = 100; (buffer 2) -> mi.mousedata = 0; (Buffer 2) -> mi.dwflags = mouseeventf_leftup; (buffer 2) -> mi.time = 0; (buffer 2) -> mi.dwextrainfo = 0;
Sendinput (3, Buffer, Sizeof (Input)); delete (buffer); Return 0;}