A method for implementing analog mouse operation 3D application
By constructing a raw input structure that simulates mouse events in shared memory and sending simulated messages, combined with the MineGetRawInputData() function for obtaining control application DLL files, the problem of not being able to control a single application or multiple applications in the existing technology is solved. This enables precise mouse operation and simultaneous control of multiple applications, thus improving the user experience.
Patent Information
- Application Number
- CN202210849035.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-07-19
- Publication Date
- 2025-12-05
- Estimated Expiration
- 2042-07-19
AI Technical Summary
In existing technologies, mouse control can only achieve system-level control, and cannot control a single application, nor can it control multiple applications simultaneously within the same system.
By constructing a structure called `raw input` in shared memory to simulate mouse events and sending simulated messages using the `PostMessage()` function, combined with the `MineGetRawInputData()` function in the control application DLL file, system messages and simulated messages can be distinguished and processed to achieve control over a single application and simultaneous control over multiple applications.
It enables precise control over individual applications and allows simultaneous control of multiple applications, improving the user experience and meeting the operational needs of multiple systems and applications.
Abstract
Description
Technical Field
[0001] This invention relates to the field of mouse event response methods, and more particularly to a method for realizing 3D applications that simulate mouse operation. Background Technology
[0002] Generally, mouse drivers are system-level, meaning that one control system can control another control system to achieve mouse control.
[0003] For example, when computer A remotely controls computer B, performing certain operations on computer A will cause the mouse on computer B to respond accordingly. This control process is system-level control. However, this process cannot control a single application, nor can it control multiple applications simultaneously. For instance, if computers A and B remotely control computer C at the same time, computer C can only respond to operations performed by computer A or computer B individually; it cannot control multiple applications simultaneously.
[0004] Therefore, existing technologies have shortcomings and need to be improved. Summary of the Invention
[0005] The purpose of this invention is to overcome the shortcomings of the prior art and provide a method for simulating mouse operation in 3D applications. This solves the problem that in the prior art, mouse control can only achieve system-level control and cannot control a single application, while also solving the problem that it is impossible to control multiple applications on the same system simultaneously.
[0006] The technical solution of the present invention is as follows: A method for simulating mouse operation in 3D applications, comprising:
[0007] The keyboard and mouse simulation program creates a shared memory and constructs a corresponding simulated mouse event structure, raw input, in the shared memory. The address of the raw input structure is used as the Hrawinput parameter, and a simulated message corresponding to the raw input structure is constructed. The PostMessage() function is then called to send the simulated message to the application.
[0008] The simulated messages include: the Hrawinput parameter, window parameter, WM_INPUT parameter, and RIM_INPUT parameter corresponding to the raw input structure. The WM_INPUT parameter is a Windows message. When a raw input event (such as mouse movement, keyboard press, gamepad operation, etc.) occurs, the operating system posts this message to the window message queue. The window parameter is the handle (HWND) of the window in the application that receives and processes the WM_INPUT message; the Hrawinput parameter is a handle contained within the WM_INPUT message, which is the address of the raw input structure. It is not data itself, but a "key" used to obtain specific, detailed raw input data through the API function GetRawInputData; the RIM_INPUT parameter is the mode flag used by the simulated mouse when registering the device.
[0009] The control application DLL file is injected into the application. The control application DLL file finds the original get function TrueGetRawInputData() in the system and replaces it with the new get function MineGetRawInputData().
[0010] The PostMessage() function is also used to send system messages to the application. Each time the PostMessage() function sends a simulated message or a system message to the application, it generates a corresponding identification information. The identification information includes the WM_INPUT parameter and the Hrawinput parameter.
[0011] The function MineGetRawInputData() is used to obtain the identification information corresponding to all simulated messages and system messages.
[0012] Each time the MineGetRawInputData() function is called in the control application DLL file, the MineGetRawInputData() function will determine whether the value of the Hrawinput parameter in its identification information is in shared memory. If it is, the message corresponding to the Hrawinput parameter is a simulated message. The application retrieves the raw input structure corresponding to the simulated message from the shared memory through the MineGetRawInputData() function and responds according to the raw input structure corresponding to the simulated message.
[0013] Preferably, the control application DLL file searches for the original acquisition function TrueGetRawInputData() in the system and replaces it with a new acquisition function MineGetRawInputData() using the HOOK Win32 API technique.
[0014] Preferably, the original acquisition function TrueGetRawInputData() is the system's original DLL file acquisition function GetRawInputData(); the acquisition function MineGetRawInputData() is the control application DLL file acquisition function GetRawInputData().
[0015] Preferably, when determining whether the value of the Hrawinput parameter in the identification information is in shared memory, if the determination result is no, it indicates that the message corresponding to the Hrawinput parameter is a system message. The application calls the original acquisition function TrueGetRawInputData() to obtain the system message and responds according to the system message.
[0016] By adopting the above solution, the present invention provides a method for simulating mouse operation in 3D applications, which has the following beneficial effects:
[0017] 1. Based on user operation event requirements, a simulated mouse event structure `rawinput` can be constructed on shared memory. The corresponding simulated message is sent to the application via the `PostMessage()` function. The system message and simulated message identification information are obtained through the `MineGetRawInputData()` function in the application DLL file. The application DLL file then calls `MineGetRawInputData()` to determine if the `Hrawinput` parameter in the identification information is in shared memory. This determines whether the message corresponding to the `Hrawinput` parameter is a system message or a simulated message. If the message is determined to be a simulated message, the application needs to further obtain the `rawinput` structure and respond accordingly to implement the corresponding mouse operation function, thus achieving the operation objective and enabling control of a single application. Simultaneously, it can distinguish and judge system messages and simulated messages, allowing the application to respond differently to different message types and perform different operations, effectively improving the user experience.
[0018] 2. Establish a connection between the simulated keyboard and mouse program and the application program, so that each application in the same system can establish a connection with the simulated keyboard and mouse program of other systems, and realize the simultaneous control of multiple applications of another system and mouse operation by different systems. Detailed Implementation
[0019] The present invention will be described in detail below with reference to specific embodiments.
[0020] This invention provides a method for simulating mouse operation in 3D applications, comprising:
[0021] The keyboard and mouse simulation program creates a shared memory space and constructs a corresponding simulated mouse event structure (raw input) in that shared memory based on the operation event requirements. The address of this raw input structure is used as the Hrawinput parameter. A simulated message corresponding to this raw input structure is then constructed, and the PostMessage() function is called to send the simulated message to the application. The operation event requirements are the mouse operations the user wants to perform; the user can directly construct the corresponding simulated mouse event structure (raw input) in the shared memory based on their operation event requirements.
[0022] Specifically, in this embodiment, the simulated message includes: the Hrawinput parameter, window parameter, WM_INPUT parameter, and RIM_INPUT parameter corresponding to the raw input structure. The address of the raw input structure in shared memory is used as the Hrawinput parameter, and then the window parameter, WM_INPUT parameter, and RIM_INPUT parameter corresponding to the raw input structure are constructed so that it can be sent to the application via the PostMessage() function. The WM_INPUT parameter is a Windows message. When a raw input event (such as mouse movement, keyboard press, gamepad operation, etc.) occurs, the operating system will post this message to the window message queue. The window parameter is the handle (HWND) of the window in the application that receives and processes the WM_INPUT message; the Hrawinput parameter is a handle contained in the WM_INPUT message, which is the address of the raw input structure. It is not data itself, but a "key" used to obtain specific, detailed raw input data through the API function GetRawInputData; the RIM_INPUT parameter is the mode flag used by the simulated mouse when registering the device.
[0023] For a detailed introduction to the PostMessage() function, please refer to the following link. https: / / docs.microsoft.com / en-us / windows / win32 / api / winuser / nf-winuser-postmessagea .
[0024] The control application DLL file can open the shared memory; the control application DLL file is injected into the application, and the control application DLL file searches for the original get function TrueGetRawInputData() in the system and replaces it with a new get function MineGetRawInputData(); specifically, the original get function TrueGetRawInputData() is the get function GetRawInputData() of the original DLL file in the system, and after finding the address of the get function GetRawInputData(), it is recorded as the get function TrueGetRawInputData(); the get function MineGetRawInputData() is the get function GetRawInputData() of the control application DLL file. The functions MineGetRawInputData() and the original TrueGetRawInputData() are similar in function. The main difference is that the original TrueGetRawInputData() can only obtain the identification information corresponding to system messages, while MineGetRawInputData() can obtain the identification information corresponding to both simulated messages and system messages. The main reason is that the raw input structure uses its address in shared memory as the Hrawinput parameter, which is not a real Hrawinput parameter. The system's TrueGetRawInputData() cannot identify and obtain it, while the replaced MineGetRawInputData() is located in the control application DLL file, not in the system, and therefore can obtain it. The function names TrueGetRawInputData() and MineGetRawInputData() are their own addresses. TrueGetRawInputData() is located in the system and is a function pointer that can point to the GetRawInputData function in user32.dll. MineGetRawInputData() is a user-defined and implemented function, which can also be used as a function pointer to point to the GetRawInputData function in the application DLL file.
[0025] For a detailed introduction to the GetRawInputData function, please refer to the following link: https: / / docs.microsoft.com / en-us / windows / win32 / api / winuser / nf-winuser- getrawinputdata .
[0026] The PostMessage() function is also used to send system messages to the application. It should be noted that, in this case, the system messages refer to the system messages of the raw input class. Each time the PostMessage() function sends a simulated message or a system message to the application, it generates corresponding identification information. The identification information includes the WM_INPUT parameter and the Hrawinput parameter.
[0027] The function MineGetRawInputData() is used to obtain the identification information corresponding to all simulated messages and system messages.
[0028] Each time the `MineGetRawInputData()` function is called in the control application DLL file, it checks whether the value of the `Hrawinput` parameter in the identification information is in shared memory. If so, the message corresponding to the `Hrawinput` parameter is a simulated message. The application retrieves the `raw input` structure corresponding to the simulated message from shared memory using `MineGetRawInputData()` and responds accordingly. After the simulated keyboard and mouse program sends the `raw input` structure to the application using the `PostMessage()` function, the application does not receive it. After the above checks, if the message corresponding to the `Hrawinput` parameter is a simulated mouse event `raw input` structure, the application will receive the `raw input` structure using `MineGetRawInputData()`.
[0029] This invention provides a method for implementing simulated mouse operations in 3D applications. It constructs a simulated mouse event structure (raw input) on shared memory based on user operation event requirements, and generates simulated messages corresponding to this raw input structure. These simulated messages are then sent to the application via the PostMessage() function. The PostMessage() function generates identification information for each simulated message sent. Since the original system function TrueGetRawInputData() can only obtain identification information for system messages and not for messages outside the system, replacing it with a new function MineGetRawInputData(), which is a pointer function to the application's DLL file, allows for the simultaneous acquisition of identification information for both system messages and simulated messages. After obtaining the identification information, the application is controlled... The application DLL file calls the function MineGetRawInputData() to retrieve data. Each time a new message is received, MineGetRawInputData() is called. At this time, MineGetRawInputData() checks whether the Hrawinput parameter in the message's identification information is in shared memory, i.e., whether its storage address belongs to shared memory. This allows the application to determine whether the message corresponding to the Hrawinput parameter is a system message or a simulated message. Since the rawinput structure corresponding to simulated messages is created in shared memory, if the result is yes, the message corresponding to the Hrawinput parameter is a simulated message. In this case, the application needs to further retrieve the rawinput structure. The system can control a single application by generating a raw input and responding accordingly to achieve the desired mouse operation. Furthermore, this invention can also control multiple applications within the same system simultaneously. For example, when computers A and B remotely control computer C, the user of computer A needs to control application H1 on computer C, and the user of computer B needs to control application H2 on computer C. In this case, the simulated keyboard and mouse program A on computer A and application H1 on computer C can establish a connection through a method described in this invention for simulating mouse operation in a 3D application. The user of computer A can then perform relevant operations based on their operation needs, enabling corresponding mouse operation functions in application H1. Similarly, the simulated keyboard and mouse program B on computer B and application H2 on computer C can establish a connection through the same method to achieve various mouse operation functions. Therefore, simultaneous control and mouse operation of multiple applications within the same system are possible.
[0030] Specifically, in this embodiment, the control application DLL file locates the address of the original get function GetRawInputData within the system, records it as the original get function TrueGetRawInputData(), and replaces it with the new get function MineGetRawInputData() using the HOOKWin32 API technology. Specifically, the Windows built-in detours tool can be used to achieve the function of HOOKWin32 API GetRawInputData().
[0031] Specifically, in this embodiment, when determining whether the value of the Hrawinput parameter in the identification information is in shared memory, if the determination result is negative, it indicates that the message corresponding to the Hrawinput parameter is a system message. The application calls the original acquisition function TrueGetRawInputData() to obtain the system message and responds accordingly. Therefore, this invention can also distinguish and determine system messages and simulated messages, enabling the application to make different responses and perform different operations based on different message types, effectively improving the user experience.
[0032] In summary, this invention provides a method for simulating mouse operation in 3D applications, which has the following beneficial effects:
[0033] 1. Based on user operation event requirements, a simulated mouse event structure `rawinput` can be constructed on shared memory. The corresponding simulated message is sent to the application via the `PostMessage()` function. The system message and simulated message identification information are obtained through the `MineGetRawInputData()` function in the application DLL file. The application DLL file then calls `MineGetRawInputData()` to determine if the `Hrawinput` parameter in the identification information is in shared memory. This determines whether the message corresponding to the `Hrawinput` parameter is a system message or a simulated message. If the message is determined to be a simulated message, the application needs to further obtain the `rawinput` structure and respond accordingly to implement the corresponding mouse operation function, thus achieving the operation objective and enabling control of a single application. Simultaneously, it can distinguish and judge system messages and simulated messages, allowing the application to respond differently to different message types and perform different operations, effectively improving the user experience.
[0034] 2. Establish a connection between the simulated keyboard and mouse program and the application program, so that each application in the same system can establish a connection with the simulated keyboard and mouse program of other systems, and realize the simultaneous control of multiple applications of another system and mouse operation by different systems.
[0035] The above are merely preferred embodiments of the present invention and are not intended to limit the present invention. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of the present invention should be included within the protection scope of the present invention.
Claims
1. A method for simulating mouse operation in 3D applications, characterized in that, include: The keyboard and mouse simulation program creates a shared memory and constructs a structure called raw input to simulate mouse events in the shared memory. The address of the raw input structure is used as the Hrawinput parameter, and a simulated message corresponding to the raw input structure is constructed. The PostMessage() function is then called to send the simulated message to the application. The simulated message includes: the Hrawinput parameter, window parameter, WM_INPUT parameter, and RIM_INPUT parameter corresponding to the raw input structure; wherein, the WM_INPUT parameter is a Windows message; the window parameter is the handle of the window in the application that receives and processes the WM_INPUT message; the Hrawinput parameter is a handle contained in the WM_INPUT message, which is the address of the raw input structure; and the RIM_INPUT parameter is the mode flag used by the simulated mouse when registering the device; The control application DLL file is injected into the application. The control application DLL file finds the original acquisition function TrueGetRawInputData() in the system and replaces it with the new acquisition function MineGetRawInputData(). The PostMessage() function is also used to send system messages to the application. Each time the PostMessage() function sends a simulated message or a system message to the application, it generates a corresponding identification information. The identification information includes: WM_INPUT parameter and Hrawinput parameter; The function MineGetRawInputData() is used to obtain the identification information corresponding to all simulated messages and system messages; Each time the MineGetRawInputData() function is called in the control application DLL file, the MineGetRawInputData() function will determine whether the value of the Hrawinput parameter in its identification information is in shared memory. If it is, the message corresponding to the Hrawinput parameter is a simulated message. The application retrieves the raw input structure corresponding to the simulated message from the shared memory through the MineGetRawInputData() function and responds according to the raw input structure corresponding to the simulated message.
2. The method for realizing simulated mouse operation in 3D applications according to claim 1, characterized in that, The control application DLL file searches for the original acquisition function TrueGetRawInputData() in the system and replaces it with the new acquisition function MineGetRawInputData() using the HOOK Win32API technique.
3. The method for realizing simulated mouse operation in 3D applications according to claim 1, characterized in that, The original retrieval function TrueGetRawInputData() is the system's original DLL file retrieval function GetRawInputData(); the retrieval function MineGetRawInputData() is the control application DLL file retrieval function GetRawInputData().
4. The method for realizing simulated mouse operation in 3D applications according to claim 1, characterized in that, When determining whether the value of the Hrawinput parameter in the identification information is in shared memory, if the determination result is no, it means that the message corresponding to the Hrawinput parameter is a system message. The application calls the original acquisition function TrueGetRawInputData() to obtain the system message and responds according to the system message.
Citation Information
Patent Citations
Method and system of simulated click test
CN103019923A
Virtual simulator and one-machine multi-mouse independent parallel control method
CN106970720A