0

im trying to automate a program on windows 10 using python, i already did it but the problem is that if my program is running i cant use my pc, so i was looking for a way to send mouse clicks and key strokes to a minimized/ unfocused window (so i can use my pc while my program is running on the background you get the idea), i was trying to use pywinauto in order to not use a more complicated library like win32api (im not a pro - im just a medicine student with too much free time) but with no luck. if some of you can be so kind an show me a way to do it, at this time i have like 2 month trying to acomplish this so i dont care if the examples use win32api as long as it is well explained (you know kindergarden like LOL).

by the way im working on python 3.

thanks in advance and sorry for my bad english it is not my native language.

  • Maybe this answer will help you: http://stackoverflow.com/a/32847266/3648361 – Vasily Ryabov May 15 '17 at 20:05
  • Just don't use methods `.click_input()` and `.type_keys()` which require the window to be active. – Vasily Ryabov May 15 '17 at 20:07
  • Ok let me explain what im doing, first im trying to connect to an existing process and sending .click() to the on top window without any success. – Victor Manuel Cortorreal May 16 '17 at 20:22
  • Maybe you just need to run Python script as an Administrator? Sometimes window messages are not passed to an app if there are no sufficient rights. We're planning to add a warning about that in next release. – Vasily Ryabov May 16 '17 at 20:41
  • yes im aware of that of that and im running my code as admin, but as i mention without success. let me show you the code maybe im doing something wrong `from pywinauto import application app = application.Application() app.connect(title_re='my app') # Access app's window object app_dialog = app.top_window_() app_dialog.Minimize() app_dialog.Click(button="Right", coords=(882, 671), double=True, absolute=False)` – Victor Manuel Cortorreal May 16 '17 at 20:51
  • Are you trying to call popup menu? I'm afraid it requires to be in foreground on the application side. If you have more details about this action maybe some workaround is possible. – Vasily Ryabov May 16 '17 at 21:17
  • no sorry i mean ".Click(button="Left", im looking to perform normal clicks, not expecting any kind of popup – Victor Manuel Cortorreal May 16 '17 at 21:36
  • by the way i have tried to start the app instead of connect to it but again without luck. – Victor Manuel Cortorreal May 16 '17 at 21:43
  • OK, the app may not handle `WM_CLICK` message, so you need to find another way to perform desired action. For the problem with app start I need more details to help you. Just edit your question to add more info. – Vasily Ryabov May 17 '17 at 06:06
  • Can you confirm that this `Click` works for active window? How about non-active and non-minimized one? – Vasily Ryabov May 17 '17 at 11:14
  • `Click()` dont work on non-active and non-minimized program so it looks like the program cant handle WM_CLICK events, it is an other way to make clicks and key types to this program ? – Victor Manuel Cortorreal May 17 '17 at 22:10
  • i also have test `post_command` and it didnt work neither – Victor Manuel Cortorreal May 19 '17 at 13:30
  • There are methods `.send_chars()` and `send_keystrokes()` (in master branch, not in 0.6.2). They are also not guaranteed to work, but you can try. `.send_keystrokes()` supports key combinations, `.send_chars()` is for single symbols only. – Vasily Ryabov May 19 '17 at 14:34
  • `.send_chars()` work as expected allowing me to send single characters to the MINIMIZED program thats really great!! now i just need to send `.Click()` commands is there a way to do it? – Victor Manuel Cortorreal May 19 '17 at 21:32
  • It's not always possible. But let's consider why you need click at specific point. Is there some control that is not visible to pywinauto as a separate one? You can try `Application(backend='uia')` and then you may see more controls in `app_dialog.print_control_identifiers()` output. The difference is described in the [Getting Started Guide](https://pywinauto.readthedocs.io/en/latest/getting_started.html). Did you ever use Inspect.exe? – Vasily Ryabov May 20 '17 at 07:49
  • i cant see any controls on inspect.exe or with print_control_identifiers() heres the result of inspect.exe : http://www.heypasteit.com/clip/0IIKWE, the program im trying to control is a game mi code generate random location click all over the screen what i mean is im not trying to click on any control. – Victor Manuel Cortorreal May 20 '17 at 23:54
  • Hmm... Not sure I can help further. Maybe creating virtual machine is the only way. – Vasily Ryabov May 22 '17 at 06:23
  • I see, i really appreciate​ your help thanks for your time. – Victor Manuel Cortorreal May 23 '17 at 14:14

0 Answers0