Controlling the top window program

202 Views Asked by At

I am wondering if in Python 3.4.2 it's possible to use EnumWindows or FindWindow periodically to select a top level window, and exclude a few programs from being selected.

I have this code that I want to run and when an error message pops up, have the code press 'okay' so the code can continue to run. To control the mouse:

import ctypes  

SetCursorPos = ctypes.windll.user32.SetCursorPos  
mouse_event = ctypes.windll.user32.mouse_event  

def left_click(x, y, clicks=1):  
  SetCursorPos(x, y)
  for i in range(clicks):  
   mouse_event(2, 0, 0, 0, 0)  
   mouse_event(4, 0, 0, 0, 0)  

left_click(480, 210)
1

There are 1 best solutions below

0
Vasily Ryabov On

I've already mentioned about pywinauto Python package that already encapsulated such EnumWindows calls and other search stuff among them. Just note that current pywinauto 0.4.2 works on Python 2.x (32-bit) only. If you need 64-bit compatible version, get latest development version of pywinauto (0.5.0+). It's already stable on Python 3.4.