Anonymous - 2008-04-17

I am using the following code to activate windows via the taskbar:

<code>
def activateTaskbarWindow(index): # this starts counting at 1
    index=int(index) # ensure integer not string
    numTrayApps=taskbar.RunningApplications.ButtonCount()
    # there are exactly twice as many windows for some reason
    bc=[taskbar.RunningApplications.GetButtonRect(i) for i in
range(numTrayApps)]
    r = bc[2*(index-1)+1] # get rectangle of desired window
    # activate foreground window with a click
    taskbar.RunningApplications.ClickInput(coords=(r.left+2,r.top+2))
    hwnd=win32gui.GetForegroundWindow()
    return hwnd
</code>

As you can see, I'm using the mouse to click on the taskbar with the
ClickInput above.

Is there an alternative method that does not use the mouse?

Thanks in advance.