如何在未聚焦/最小化的窗口中模拟鼠标/键盘事件? [英] How to emulate mouse/keyboard events in a unfocused/minimized window?

查看:189
本文介绍了如何在未聚焦/最小化的窗口中模拟鼠标/键盘事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Python进行一些自动化,但是我想执行它,并且仍然能够自由使用我的机器.因此,我正在使用PyWin32来模拟一些单击和键入,但是只有在窗口处于打开状态且焦点对准的情况下运行脚本时,它才有效.

I am trying to do some automation with Python, but I want to execute it and still being able to use my machine freely. So I am using PyWin32 to emulate some clicks and typing but it only works if I run the script while the window is open and focused.

有一种方法可以使我的脚本仅集中在一个窗口上,并且即使该窗口未聚焦(即使在最小化时也可以正常工作),仍然可以在不控制鼠标的情况下单击该窗口. !)?

There is a way to make my script only focus on a window, and still be able to click on that window without taking control over the mouse, even if the window is not focused (if it works when is minimized, is best!)?

推荐答案

我不知道PyWin32软件包,但是从win32 api的角度来看,这应该很容易. 获取该窗口的HWND并将所需的事件发布(PostMessage)到该窗口.

i do not know the PyWin32 package but from a win32 api point of view the thing should be easy. get a HWND of that window and post (PostMessage) the events you want to the window.

例如:WM_LBUTTONDOWN& WM_LBUTTONUP,WM_RBUTTONDOWN& WM_RBUTTONUP,WM_MOUSEMOVE ...

eg: WM_LBUTTONDOWN & WM_LBUTTONUP, WM_RBUTTONDOWN & WM_RBUTTONUP, WM_MOUSEMOVE...

看看win32帮助中如何设置wParam&特定事件的lParam数据.

look at the win32 help how to set the wParam & lParam data for the specific events.

我以这种方式控制了《暗黑破坏神3》;)

i controlled diablo 3 this way for example ;)


无需为此集中注意力或将其最大化


there is no need to be in focus or maximized for this

编辑
也许您应该照顾autoit,这是一种用于窗口自动化的广泛使用的脚本语言.我从未使用过它,但在这种情况下经常阅读该名称.它也可以在python中使用.

Edit
may be you should look after autoit, a widely used scrip language for window automation. I never used it but read the name very often in this context. it may also be usable from python.

这篇关于如何在未聚焦/最小化的窗口中模拟鼠标/键盘事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆