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

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

Answers


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.


Need Your Help

How can I grant a specific role In Ubercart?

php drupal content-management-system e-commerce ubercart

I'm trying to grant a specific role to users that order an amount equal or greater than 100.00 €: Conditional Actions is going really near the achievement, but I'm failing on the action (PHP requir...