Synchronization method and device for mouse event of Windows, equipment and medium
By listening to mouse events in Windows system and calculating relative coordinates for synchronization processing, the problem of mouse events synchronization with different screen resolutions is solved, and the CPU burden is reduced by merging scroll wheel events, improving user experience and device performance.
Patent Information
- Application Number
- CN202411962984.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-30
- Publication Date
- 2025-05-02
AI Technical Summary
In Windows systems, multiple screens are used and the screen resolutions are different, there is a problem of position error in mouse events synchronization, and the high frequency of scroll wheel events leads to a sharp increase in hardware CPU usage, resulting in device stuttering or stuck.
By listening to the mouse events of the main control window, obtain the DPI values of the main control window and slave control window, calculate the relative coordinates for synchronization processing, and when the frequency of the scroll event is high, merge the scroll events in the same direction to reduce the burden on the CPU.
It realizes accurate synchronization of mouse events on multiple screens with different resolutions, improving user experience and reducing device lag problems caused by scroll wheel events.
Smart Images

Figure CN119917301A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of information processing technology, and in particular to a synchronization method, device, equipment and medium for mouse events in Windows. Background Art
[0002] There is a synchronizer in the existing Windows system, which is used to synchronize the operation of the master application and the slave application. When the synchronizer is used on the same screen, the master application and the slave application are laid out on the screen, and there is no problem with the synchronization of mouse events. However, when the user uses multiple screens with different screen resolutions, the position of mouse event synchronization will be wrong.
[0003] In addition, due to hardware limitations, when synchronizing the scroll wheel events in the mouse events, the user opens multiple slave control applications, and the scroll wheel events have the characteristics of long time and high frequency. When the user uses the laptop touchpad, the scroll wheel event will instantly reach a frequency of 30 to 50 times, which causes the hardware CPU usage rate to increase rapidly in a short period of time, and then cause the user's device to freeze or freeze. Summary of the invention
[0004] The technical problem to be solved by the present invention is to provide a method, device, equipment and medium for synchronizing mouse events for Windows, so as to ensure that mouse events can still be accurately synchronized on multiple screens with different resolutions, thereby improving the user experience.
[0005] In a first aspect, the present invention provides a method for synchronizing mouse events in Windows, which is used for a Windows synchronizer, wherein the Windows synchronizer is used for synchronizing a master window and a slave window; the method comprises the following steps:
[0006] Step 1: Monitor the mouse events of the main control window and save them to the execution queue;
[0007] Step 2: Obtain the first DPI value of the screen of the main control window, and obtain the first relative coordinates of the mouse relative to the upper left corner of the main control window;
[0008] Step 3: The master control window sends the mouse events and the first DPI value in the execution queue to the slave control window, and obtains the second DPI value of the screen of the slave control window. If the first DPI value is equal to the second DPI value, the slave control window executes the corresponding mouse event according to the first relative coordinates; otherwise, the second relative coordinates of the slave control window are calculated as:
[0009] Second relative coordinate = first relative coordinate ÷ first DPI value × second DPI value;
[0010] The slave control window executes the corresponding mouse event according to the second relative coordinates.
[0011] In a second aspect, the present invention provides a synchronization device for mouse events in Windows, which is used for a Windows synchronizer, wherein the Windows synchronizer is used for synchronizing a master window and a slave window; the device comprises the following steps:
[0012] The event monitoring module monitors the mouse events of the main control window and saves them to the execution queue;
[0013] The information acquisition module acquires the first DPI value of the screen of the main control window and acquires the first relative coordinate of the mouse relative to the upper left corner of the main control window;
[0014] The synchronization module is executed, and the master control window sends the mouse events and the first DPI value in the execution queue to the slave control window, and obtains the second DPI value of the screen of the slave control window. If the first DPI value is equal to the second DPI value, the slave control window executes the corresponding mouse event according to the first relative coordinate; otherwise, the second relative coordinate of the slave control window is calculated as:
[0015] Second relative coordinate = first relative coordinate ÷ first DPI value × second DPI value;
[0016] The slave control window executes the corresponding mouse event according to the second relative coordinates.
[0017] In a third aspect, the present invention provides an electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the method described in the first aspect when executing the program.
[0018] In a fourth aspect, the present invention provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the method described in the first aspect.
[0019] One or more technical solutions provided by the present invention have at least the following technical effects or advantages:
[0020] When a user uses multiple screens with different resolutions, the technical solution of the present invention ensures that mouse events can be accurately synchronized on multiple screens with different resolutions without the need for the user to perform screen settings, thereby improving the user experience.
[0021] The technical solution of the present invention detects the execution frequency of Windows mouse wheel events. When the execution frequency is too high, the wheel events in the same direction within a certain period of time are combined and sent, the scrolling distance is calculated, and they are merged into a new Windows mouse wheel event for execution, thereby reducing the burden of executing the scrolling operation on the CPU, thereby solving the problem of jamming and freezing caused by insufficient performance of user equipment or high-frequency scrolling of a large number of slave control windows, and increasing the number of windows that can be synchronized by users.
[0022] The above description is only an overview of the technical solution of the present invention. In order to more clearly understand the technical means of the present invention, it can be implemented according to the contents of the specification. In order to make the above and other purposes, features and advantages of the present invention more obvious and easy to understand, the specific implementation methods of the present invention are listed below. BRIEF DESCRIPTION OF THE DRAWINGS
[0023] The present invention will be further described below in conjunction with embodiments with reference to the accompanying drawings.
[0024] Figure 1 is a flow chart of the method in Embodiment 1 of the present invention;
[0025] Figure 2 It is a schematic diagram of the structure of the device in the second embodiment of the present invention. DETAILED DESCRIPTION
[0026] The embodiments of the present application provide a method, device, equipment and medium for synchronizing mouse events in Windows to solve the technical problem in the prior art that different screen resolutions cannot be synchronized, and during synchronization, smooth operation is ensured based on the performance of the hardware.
[0027] Embodiment 1
[0028] like Figure 1 As shown, this embodiment provides a method for synchronizing mouse events for Windows, which is used for a Windows synchronizer, and the Windows synchronizer is used for synchronizing a master window and a slave window; the method comprises the following steps:
[0029] Step 1: Monitor the mouse events of the main control window and save them to the execution queue;
[0030] Step 2: Obtain the first DPI value of the screen of the main control window, and obtain the first relative coordinates of the mouse relative to the upper left corner of the main control window;
[0031] Step 3: The master control window sends the mouse events and the first DPI value in the execution queue to the slave control window, and obtains the second DPI value of the screen of the slave control window. If the first DPI value is equal to the second DPI value, the slave control window executes the corresponding mouse event according to the first relative coordinates; otherwise, the second relative coordinates of the slave control window are calculated as:
[0032] Second relative coordinate = first relative coordinate ÷ first DPI value × second DPI value;
[0033] The slave control window executes the corresponding mouse event according to the second relative coordinates.
[0034] In this embodiment, preferably, the step 1 specifically includes: using win32gui.SetWindows HookEx in conjunction with win32con.WH_MOUSE to monitor the mouse events of the main control window, and saving them to the execution queue.
[0035] In this embodiment, preferably, step 2 is specifically: use ctypes.windll.user32.GetDpiForWindow(hwnd) to obtain the first DPI value of the display screen of the main control window; obtain the third relative coordinates of the mouse of the main control window relative to the screen, obtain the upper left corner coordinates of the main control window, and then calculate the first relative coordinates of the mouse and the upper left corner coordinates of the main control window.
[0036] In this embodiment, preferably, the step 3 is specifically as follows: the mouse event includes: a click event, a move event and a scroll event;
[0037] The master window sends the first DPI value to the slave window, and obtains the second DPI value of the screen of the slave window. If the first DPI value is equal to the second DPI value, the slave window executes the corresponding mouse event according to the first relative coordinate; otherwise, the second relative coordinate of the slave window is calculated as follows: the second relative coordinate = the first relative coordinate ÷ the first DPI value × the second DPI value;
[0038] If the mouse event is a click event or a move event, the master control window sends the mouse event in the execution queue to the slave control window; the slave control window uses win32gui.SendMessage with the win32con library to execute the corresponding mouse event according to the second relative coordinate;
[0039] If the mouse event is a scrolling event, the device CPU usage and memory usage are obtained in real time. If the CPU usage is less than the first set threshold and the memory usage is less than the second set threshold, the main control window sends the mouse event in the execution queue to the slave control window; the slave control window uses win32gui.SendMessage in combination with the win32con library to execute the corresponding mouse event according to the second relative coordinate; otherwise, a delay time is set. If the scrolling events obtained within the delay time are all in the same direction and are all scrolling events, all scrolling events in the execution queue corresponding to the delay time are obtained and merged into a scrolling merge event; if there are scrolling events or other events in the opposite direction within the delay time, all previous scrolling events in the execution queue are combined to obtain a scrolling merge event, and the main control window sends the scrolling merge event to the slave control window; the slave control window uses win32gui.SendMessage in combination with win32con.WM_MOUSEWHEEL to execute the scrolling merge event according to the second relative coordinate.
[0040] Based on the same inventive concept, the present application also provides a device corresponding to the method in Example 1, see Example 2 for details.
[0041] Embodiment 2
[0042] like Figure 2 As shown, a synchronization device for mouse events of Windows is used for a Windows synchronizer, and the Windows synchronizer is used for synchronizing a master window and a slave window; it includes the following steps:
[0043] The event monitoring module monitors the mouse events of the main control window and saves them to the execution queue;
[0044] The information acquisition module acquires the first DPI value of the screen of the main control window and acquires the first relative coordinate of the mouse relative to the upper left corner of the main control window;
[0045] The synchronization module is executed, and the master control window sends the mouse events and the first DPI value in the execution queue to the slave control window, and obtains the second DPI value of the screen of the slave control window. If the first DPI value is equal to the second DPI value, the slave control window executes the corresponding mouse event according to the first relative coordinate; otherwise, the second relative coordinate of the slave control window is calculated as:
[0046] Second relative coordinate = first relative coordinate ÷ first DPI value × second DPI value;
[0047] The slave control window executes the corresponding mouse event according to the second relative coordinates.
[0048] In this embodiment, preferably, the step 1 specifically includes: using win32gui.SetWindows HookEx in conjunction with win32con.WH_MOUSE to monitor the mouse events of the main control window, and saving them to the execution queue.
[0049] In this embodiment, preferably, step 2 is specifically: use ctypes.windll.user32.GetDpiForWindow(hwnd) to obtain the first DPI value of the display screen of the main control window; obtain the third relative coordinates of the mouse of the main control window relative to the screen, obtain the upper left corner coordinates of the main control window, and then calculate the first relative coordinates of the mouse and the upper left corner coordinates of the main control window.
[0050] In this embodiment, preferably, the step 3 is specifically as follows: the mouse event includes: a click event, a move event and a scroll event;
[0051] The master window sends the first DPI value to the slave window, and obtains the second DPI value of the screen of the slave window. If the first DPI value is equal to the second DPI value, the slave window executes the corresponding mouse event according to the first relative coordinate; otherwise, the second relative coordinate of the slave window is calculated as follows: the second relative coordinate = the first relative coordinate ÷ the first DPI value × the second DPI value;
[0052] If the mouse event is a click event or a move event, the master control window sends the mouse event in the execution queue to the slave control window; the slave control window uses win32gui.SendMessage with the win32con library to execute the corresponding mouse event according to the second relative coordinate;
[0053] If the mouse event is a scrolling event, the device CPU usage and memory usage are obtained in real time. If the CPU usage is less than the first set threshold and the memory usage is less than the second set threshold, the main control window sends the mouse event in the execution queue to the slave control window; the slave control window uses win32gui.SendMessage in conjunction with the win32con library to execute the corresponding mouse event; otherwise, a delay time is set. If the scrolling events obtained within the delay time are all in the same direction and are all scrolling events, all scrolling events in the execution queue corresponding to the delay time are obtained and merged into a scrolling merge event; if there are scrolling events or other events in the opposite direction within the delay time, all previous scrolling events in the execution queue are combined to obtain a scrolling merge event, and the main control window sends the scrolling merge event to the slave control window; the slave control window uses win32gui.SendMessage in conjunction with win32con.WM_MOUSEWHEEL to execute the scrolling merge event.
[0054] Since the device introduced in the second embodiment of the present invention is a device used to implement the method of the first embodiment of the present invention, those skilled in the art can understand the specific structure and deformation of the device based on the method introduced in the first embodiment of the present invention, so it is not described here in detail. All devices used in the method of the first embodiment of the present invention belong to the scope of protection of the present invention.
[0055] Based on the same inventive concept, the present application provides an electronic device embodiment corresponding to the first embodiment, see the third embodiment for details.
[0056] Embodiment 3
[0057] This embodiment provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, any implementation method in the first embodiment can be implemented.
[0058] Since the electronic device introduced in this embodiment is a device used to implement the method in the first embodiment of the present application, based on the method introduced in the first embodiment of the present application, a person skilled in the art can understand the specific implementation of the electronic device of the present embodiment and its various variations, so how the electronic device implements the method in the embodiment of the present application is not described in detail here. As long as a person skilled in the art implements the device used by the method in the embodiment of the present application, it belongs to the scope of protection of the present application.
[0059] Based on the same inventive concept, the present application provides a storage medium corresponding to the first embodiment, see the fourth embodiment for details.
[0060] Embodiment 4
[0061] This embodiment provides a computer-readable storage medium on which a computer program is stored. When the computer program is executed by a processor, any implementation method in the first embodiment can be implemented.
[0062] Those skilled in the art will appreciate that embodiments of the present invention may be provided as methods, systems, or computer program products. Therefore, the present invention may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Moreover, the present invention may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0063] The present invention is described with reference to flowcharts and / or block diagrams of methods, devices (systems), and computer program products according to embodiments of the present invention. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0064] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture including an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0065] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process in the computer or other programmable device. Figure 1 A process or multiple processes and / or boxes Figure 1 A step that specifies a function in one or more boxes.
[0066] Although the specific implementation modes of the present invention are described above, those skilled in the art should understand that the specific implementation modes described are only illustrative and are not intended to limit the scope of the present invention. Equivalent modifications and changes made by those skilled in the art in accordance with the spirit of the present invention should be included in the scope of protection of the claims of the present invention.
Claims
1. A method for synchronizing mouse events in Windows, used in a Windows synchronizer, wherein the Windows synchronizer is used for synchronizing a master window and a slave window; characterized in that: The steps include: Step 1: Monitor the mouse events of the main control window and save them to the execution queue; Step 2: Obtain the first DPI value of the screen of the main control window, and obtain the first relative coordinates of the mouse relative to the upper left corner of the main control window; Step 3: The master control window sends the mouse events and the first DPI value in the execution queue to the slave control window, and obtains the second DPI value of the screen of the slave control window. If the first DPI value is equal to the second DPI value, the slave control window executes the corresponding mouse event according to the first relative coordinates; otherwise, the second relative coordinates of the slave control window are calculated as: Second relative coordinate = first relative coordinate ÷ first DPI value × second DPI value; The slave control window executes the corresponding mouse event according to the second relative coordinates.
2. A method for synchronizing mouse events in Windows according to claim 1, characterized in that: The step 1 is specifically: using win32gui.SetWindowsHookEx in conjunction with win32con.WH_MOUSE to monitor the mouse events of the main control window and save them to the execution queue.
3. A method for synchronizing mouse events in Windows according to claim 1, characterized in that: The step 2 is specifically as follows: using ctypes.windll.user32.GetDpiForWind ow(hwnd) to obtain the first DPI value of the display screen of the main control window; obtaining the third relative coordinates of the mouse of the main control window relative to the screen, obtaining the upper left corner coordinates of the main control window, and then calculating the first relative coordinates of the mouse and the upper left corner coordinates of the main control window.
4. A method for synchronizing mouse events in Windows according to claim 1, characterized in that: The step 3 is specifically as follows: the mouse events include: click events, move events and scroll events; The master window sends the first DPI value to the slave window, and obtains the second DPI value of the screen of the slave window. If the first DPI value is equal to the second DPI value, the slave window executes the corresponding mouse event according to the first relative coordinate; otherwise, the second relative coordinate of the slave window is calculated as follows: the second relative coordinate = the first relative coordinate ÷ the first DPI value × the second DPI value; If the mouse event is a click event or a move event, the master control window sends the mouse event in the execution queue to the slave control window; the slave control window uses win32gui.SendMessage with the win32con library to execute the corresponding mouse event according to the second relative coordinate; If the mouse event is a scrolling event, the device CPU usage and memory usage are obtained in real time. If the CPU usage is less than the first set threshold and the memory usage is less than the second set threshold, the main control window sends the mouse event in the execution queue to the slave control window; the slave control window uses win32gui.SendMessage in combination with the win32con library to execute the corresponding mouse event according to the second relative coordinate; otherwise, a delay time is set. If the scrolling events obtained within the delay time are all in the same direction and are all scrolling events, all scrolling events in the execution queue corresponding to the delay time are obtained and merged into a scrolling merge event; if there are scrolling events or other events in the opposite direction within the delay time, all previous scrolling events in the execution queue are combined to obtain a scrolling merge event, and the main control window sends the scrolling merge event to the slave control window; the slave control window uses win32gui.SendMessage in combination with win32con.WM_MOUSEWHEEL to execute the scrolling merge event according to the second relative coordinate.
5. A synchronization device for mouse events of Windows, used for a Windows synchronizer, wherein the Windows synchronizer is used for synchronizing a master window and a slave window; characterized in that: The steps include: The event monitoring module monitors the mouse events of the main control window and saves them to the execution queue; The information acquisition module acquires the first DPI value of the screen of the main control window and acquires the first relative coordinate of the mouse relative to the upper left corner of the main control window; The synchronization module is executed, and the master control window sends the mouse events and the first DPI value in the execution queue to the slave control window, and obtains the second DPI value of the screen of the slave control window. If the first DPI value is equal to the second DPI value, the slave control window executes the corresponding mouse event according to the first relative coordinate; otherwise, the second relative coordinate of the slave control window is calculated as: Second relative coordinate = first relative coordinate ÷ first DPI value × second DPI value; The slave control window executes the corresponding mouse event according to the second relative coordinates.
6. A synchronization device for mouse events in Windows according to claim 5, characterized in that: The step 1 is specifically: using win32gui.SetWindowsHookEx in conjunction with win32con.WH_MOUSE to monitor the mouse events of the main control window and save them to the execution queue.
7. A synchronization device for mouse events in Windows according to claim 5, characterized in that: The step 2 is specifically as follows: using ctypes.windll.user32.GetDpiForWind ow(hwnd) to obtain the first DPI value of the display screen of the main control window; obtaining the third relative coordinates of the mouse of the main control window relative to the screen, obtaining the upper left corner coordinates of the main control window, and then calculating the first relative coordinates of the mouse and the upper left corner coordinates of the main control window.
8. A synchronization device for mouse events in Windows according to claim 5, characterized in that: The step 3 is specifically as follows: the mouse events include: click events, move events and scroll events; The master window sends the first DPI value to the slave window, and obtains the second DPI value of the screen of the slave window. If the first DPI value is equal to the second DPI value, the slave window executes the corresponding mouse event according to the first relative coordinate; otherwise, the second relative coordinate of the slave window is calculated as follows: the second relative coordinate = the first relative coordinate ÷ the first DPI value × the second DPI value; If the mouse event is a click event or a move event, the master control window sends the mouse event in the execution queue to the slave control window; the slave control window uses win32gui.SendMessage with the win32con library to execute the corresponding mouse event according to the second relative coordinate; If the mouse event is a scrolling event, the device CPU usage and memory usage are obtained in real time. If the CPU usage is less than the first set threshold and the memory usage is less than the second set threshold, the main control window sends the mouse event in the execution queue to the slave control window; the slave control window uses win32gui.SendMessage in conjunction with the win32con library to execute the corresponding mouse event; otherwise, a delay time is set. If the scrolling events obtained within the delay time are all in the same direction and are all scrolling events, all scrolling events in the execution queue corresponding to the delay time are obtained and merged into a scrolling merge event; if there are scrolling events or other events in the opposite direction within the delay time, all previous scrolling events in the execution queue are combined to obtain a scrolling merge event, and the main control window sends the scrolling merge event to the slave control window; the slave control window uses win32gui.SendMessage in conjunction with win32con.WM_MOUSEWHEEL to execute the scrolling merge event.
9. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the program, the method according to any one of claims 1 to 4 is implemented.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the method according to any one of claims 1 to 4 is implemented.