How to emulate mouse/keyboard events in a unfocused/minimized window?

拈花ヽ惹草 提交于 2019-12-11 13:32:00

问题


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!)?


回答1:


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.

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

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

i controlled diablo 3 this way for example ;)

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

Edit 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.



来源:https://stackoverflow.com/questions/22214115/how-to-emulate-mouse-keyboard-events-in-a-unfocused-minimized-window

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!