简体   繁体   中英

How to get real mouse movement, not based on cursor position (python)

Im using windows and python

So I want to make a macro in a game, but the game always centers your mouse at the center of the screen. Every mouse movement algorithm only detects movements based on the difference between the previous cursor and the current cursor. Is there a way to detect mouse movement instead of cursor position?

Mouse movement is an event. So this event needs to be captured. Windows sends a WM_MOUSEMOVE message when the mouse moves. Various Python extensions can work with this event. Eg tkinter does this as follows:

import tkinter as tk
root = tk.Tk()
    
def motion(event):
    print('the mouse moved')
    
root.bind('<Motion>', motion)
root.mainloop()

When the mouse moves in the open window, it is reported that the mouse has moved. Are you looking for something like that?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM