win32: moving mouse with SetCursorPos vs. mouse_event

2024/10/1 19:41:42

Is there any difference between moving the mouse in windows using the following two techniques?

win32api.SetCursorPos((x,y))

vs:

nx = x*65535/win32api.GetSystemMetrics(0)
ny = y*65535/win32api.GetSystemMetrics(1)
win32api.mouse_event(win32con.MOUSEEVENTF_ABSOLUTE|win32con.MOUSEEVENTF_MOVE,nx,ny)

Does anything happen differently in the way Windows processes the movements?

Answer

I believe that mouse_event works by inserting the events into the mouse input stream where as SetCursorPos just moves the cursor around the screen. I don't believe that SetCursorPos generates any input events either (though I may be wrong).

The practical implications are that when you use SetCursorPos, it just moves the cursor around. Where as when you use mouse_event, it inserts the events in the input stream which will in turn generate input events for any programs that are listening. This has implications with programs that listen for lower level mouse events rather than just cursor clicks; games for instance. Also, if you're using mouse_event to move the cursor around and have cursor/pointer acceleration on, than the resulting mouse motion should be subject to whatever acceleration curves windows is using.

https://en.xdnf.cn/q/70930.html

Related Q&A

Pandas: Unstacking One Column of a DataFrame

I want to unstack one column in my Pandas DataFrame. The DataFrame is indexed by the Date and I want to unstack the Country column so each Country is its own column. The current pandas DF looks like t…

python-polars split string column into many columns by delimiter

In pandas, the following code will split the string from col1 into many columns. is there a way to do this in polars? d = {col1: ["a/b/c/d", "a/b/c/d"]} df= pd.DataFrame(data=d) df…

pylint giving not-callable error for object property that is callable

Not sure if I am doing something wrong or if this is a problem with pylint. In the code below I get a linting error that self.type is not callable E1102.Although I could just ignore it and keep workin…

ModuleNotFoundError: No module named api

I created a Django project inside of api folder called bucks:api |____ categories/|____ __init__.py|____ ...|____ models.py|____ tests.py|____ views.py |____ .../ |____ bucks/ |____ users/|____ __init_…

Reading csv header white space and case insensitive

Is there a possibility to read the header of a CSV file white space and case insensitive? As for now I use csv.dictreader like this:import csv csvDict = csv.DictReader(open(csv-file.csv, rU))# determi…

How to remove the seconds of Pandas dataframe index?

Given a dataframe with time series that looks like this:Close 2015-02-20 14:00:00 1200.1 2015-02-20 14:10:00 1199.8 2015-02-21 14:00:00 1199.3 2015-02-21 14:10:00 1199.0 2015-02-22 14:00:00 1198.4…

Slow loading SQL Server table into pandas DataFrame

Pandas gets ridiculously slow when loading more than 10 million records from a SQL Server DB using pyodbc and mainly the function pandas.read_sql(query,pyodbc_conn). The following code takes up to 40-4…

compress a string in python 3?

I dont understand in 2.X it worked :import zlib zlib.compress(Hello, world)now i have a :zlib.compress("Hello world!") TypeError: must be bytes or buffer, not strHow can i compress my string …

How to set color of text using xlwt

I havent been able to find documentation on how to set the color of text. How would the following be done in xlwt?style = xlwt.XFStyle()# bold font = xlwt.Font() font.bold = True style.font = font# ba…

How to apply linregress in Pandas bygroup

I would like to apply a scipy.stats.linregress within Pandas ByGroup. I had looked through the documentation but all I could see was how to apply something to a single column like grouped.agg(np.sum)or…