Fourth, the action simulation technology we introduced before, almost all games have a lot of cumbersome and boring attack actions to increase the player's skills, and those who have not finished the maze, these seem to be synonymous with the role game. Now, plug-in can help players from these cumbersome works, focus on the progress of the game plot. The plug-in program is required to implement functional functions such as automatic role position and automatic attacks, need to use keyboard simulation technology and mouse simulation technology. Below we will focus on these techniques and prepare a simple instance to help readers understand the implementation of action simulation technology. 1. Mouse simulation technology uses a mouse in almost all games to change the position and direction of the role. Players can use only a small mouse to enable the role to swim. So, how do we implement the role without players, can also walk automatically. In fact, this is not difficult, just a few Windows API functions can be customized, let us first understand these API functions. (1) Simulate the mouse action API function mouse_event, which can implement an analog mouse to press and release the action.
Void mouse_event (DWORD DWFLAGS, / / mouse action ID. DWORD DX, / / mouse horizontal direction. DWORD DY, / / Mouse vertical position. DWORD DWDATA, // Mouse wheel rotation Number. DWORD DWEXTRAINFO // An associated mouse Auxiliary information.);
Among them, DWFlags expressed a wide variety of mouse action and click activities, and its common value is as follows: MouseEventf_move represents analog mouse mobile event. MouseEventf_leftdown indicates that the analog presses the left mouse button. MouseEventf_leftUp indicates that the simulation releases the left mouse button. MouseEventf_rightdown indicates that the analog is right-click. MouseEventf_rightUp indicates that the analog releases the right mouse button. MouseEventf_middledown indicates that the analog Press the mouse button. MouseEventf_middleUp indicates that the analog release mouse button. (2) Set and get the API function of the current mouse position. Get the current mouse location Use the getCursorPos () function, set the current mouse location to use the setCursorpos () function.
Bool getCursorpos (LPPOINT LPPOINT // Returns the current location of the mouse.); Bool SetCursorpos (horizontal direction of the INT X, / / mouse. The vertical position of the int y // mouse.);
Usually the walking role is moving through the mouse to the destination, then press the button to press the button. Below we use the API function described above to simulate the role walking process.
Cpoint OldPoint, NewPoint; getCursorpos (& OLDPOINT); // Save the current mouse position. NewPoint.x = OldPoint.x 40; newpoint.y = OldPoint.y 10; setCursorpos (NewPoint.x, NewPoint.y); // Set the destination location. Mouse_Event (MouseEventf_RightDown, 0, 0, 0); // The analog is right-click on the mouse button. Mouse_event (MouseEventf_Rightup, 0, 0, 0); // Simulate the right mouse button.
2. Keyboard Simulation Technology In many games, but also provides a mouse operation, but also provides a keyboard operation, and shortcuts can be used when attacking the attack object. In order to make these attacks automatically, the plug-in program needs to use keyboard simulation technology. Like mouse simulation technology, Windows API also provides a series of API functions to complete analog to keyboard actions. Analog Keyboard Action API Function Keydb_Event, which simulates an action on a keyboard on a keyboard to perform or release actions. Void keybd_event (Byte BVK, // Virtual key value. Byte BSCAN, / / hardware scanning code. DWORD DWFLAGS, // Auxiliary information associated with keyboard action.);
Where BVK represents the virtual key value, it is a macro of a BYTE type value, which ranges from 1-254. For the virtual key values, please use the keyword "Virtual-Key Codes" to find relevant information on the MSDN. BSCAN means that when a key is pressed and released on the keyboard, the keyboard system hardware generated scan code, we can convert between the MapVirtualKey () function between the virtual key value and the scan code. DWFlags represents a variety of keyboard actions, which have two values: KeyEventf_extendedKey and KeyEventf_Keyup. Below we use a code to implement the Shift R shortcut to attack the attack object in the game.
KeyBD_Event (VK_Control, MapVirtualKey (vk_control, 0), 0, 0); // Press the CTRL button. KeyBD_Event (0x52, MapVirtualKey (0x52, 0), 0, 0); // Under the R key. KeyBD_EVENT (0x52, MapVirtualKey (0x52, 0), KeyEventf_keyup, 0); // release the R key. KeyBD_EVENT (VK_Control, MapVirtualKey (vk_control, 0), keyeventf_keyup, 0); // release the CTRL button.
3. The mouse and keyboard simulation technique described above to activate the simulation of the action part of the game role, but you need to hang the game above the game, you need to connect it to the game's scene window or use a activation key, The activation key like a button crest. We can use the getWindow function to enumerate the window, or you can use the FindWindow function to find a specific window. There is another findwindowex function to find the sub-window of the window. When the game is switched, we can use FindWindowEx to determine some of the characteristics of the current window, thus judge whether it is still in this scene, the method is much more, such as getWindowInfo to determine something For example, when you find a button, you will explain the game scene has been switched. When using the activation key, you need to develop a full keyboard hook using the Hook technology, which does not specifically introduce the development process of the global hook, in the later examples, we will use the global hook, will learn the global hook Related knowledge.