简体   繁体   English

Python win32gui 获取 Z05B8C74CBD96FBF2DEZC1A5F4 中虚拟 cursor 的当前 position

[英]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.我知道使用win32gui.PostMessage(hwnd, win32con.WM_MOUSEMOVE, wParam, lParam)我可以在不影响我真正的鼠标的情况下将鼠标移动到没有焦点的应用程序上。

How can I get my current "fake mouse" position if win32api.GetCursorPos() returns the position of my real mouse cursor?如果win32api.GetCursorPos()返回我的真实鼠标 cursor 的 position,我如何获得当前的“假鼠标”position?

Edit #1:编辑#1:

I am using WM_MOUSEMOVE on an external application, thus the only thing I have is the application's window handle (HWND).我在外部应用程序上使用WM_MOUSEMOVE ,因此我唯一拥有的是应用程序的window handle (HWND)。

You can use GetMessagePos :您可以使用GetMessagePos

Retrieves the cursor position for the last message retrieved by the GetMessage function.检索由GetMessage function 检索到的最后一条消息的 cursor position。

More reference: Possible to do MouseMove actions with PostMessage without hijacking the cursor?更多参考: 在不劫持 cursor 的情况下,可以使用 PostMessage 执行 MouseMove 操作吗?

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.如果你只想通过外部应用程序的HWND获取它的消息,你需要使用SetWindowsHookEx ,将其做成一个dll注入到外部进程中。

You can use SetWindowsHookEx function, with WH_CALLWNDPROC or some other type of hook, and here is an example.您可以将SetWindowsHookEx function 与WH_CALLWNDPROC或其他类型的钩子一起使用, 是一个示例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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