python change window focus

Solutions on MaxInterview for python change window focus by the best coders in the world

showing results for - "python change window focus"
Dirk
05 Apr 2019
1import win32gui
2
3def windowEnumerationHandler(hwnd, top_windows):
4    top_windows.append((hwnd, win32gui.GetWindowText(hwnd)))
5
6if __name__ == "__main__":
7    results = []
8    top_windows = []
9    win32gui.EnumWindows(windowEnumerationHandler, top_windows)
10    for i in top_windows:
11        if "notepad" in i[1].lower():
12            print i
13            win32gui.ShowWindow(i[0],5)
14            win32gui.SetForegroundWindow(i[0])
15            break