Windows 7: how to bring a window to the front no matter what other window has focus?

后端 未结 9 1756
走了就别回头了
走了就别回头了 2020-11-28 08:04

I\'m implementing a task-bar replacement, dock-like application-switcher style program. It\'s doing some unique stuff with OpenGL, and with keyboard shortcuts, so the way it

9条回答
  •  無奈伤痛
    2020-11-28 09:04

    I don't like these suggestions of using win32gui because you can't easily install that via pip. So here's my solution:

    First, install pywinauto via pip. If you're on Python 2.7.9 or a newer version on the 2 branch, or Python 3.4.0 or a newer version from the 3 branch, pip is already installed. For everyone else, update Python to get it (or you can manually download and install it by running this script, if you must run an older version of Python.)

    Just run this from the command line (not from within Python):

    pip install pywinauto
    

    Next, import what you need from pywinauto:

    from pywinauto.findwindows    import find_window
    from pywinauto.win32functions import SetForegroundWindow
    

    Finally, it's just one actual line:

    SetForegroundWindow(find_window(title='taskeng.exe'))
    

提交回复
热议问题