简体   繁体   中英

Python win32gui get current position of the virtual cursor in a window

I know that using win32gui.PostMessage(hwnd, win32con.WM_MOUSEMOVE, wParam, lParam) I can fake mouse movement to an unfocused application, without effecting my real mouse.

How can I get my current "fake mouse" position if win32api.GetCursorPos() returns the position of my real mouse cursor?

Edit #1:

I am using WM_MOUSEMOVE on an external application, thus the only thing I have is the application's window handle (HWND).

You can use GetMessagePos :

Retrieves the cursor position for the last message retrieved by the GetMessage function.

More reference: Possible to do MouseMove actions with PostMessage without hijacking the cursor?

Edit

If you only want to get its messages through the HWND of the external application, you need to use SetWindowsHookEx and make it into a dll to inject it into the external process.

You can use SetWindowsHookEx function, with WH_CALLWNDPROC or some other type of hook, and here is an example.

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