更改活动 Window

Change the active Window

我正在寻找一种设置活动 window 的方法。我找到的唯一解决方案已经过时。它们包括像 pywinauto 这样的模块,但它的 focus() 功能不起作用。

我需要一些可以快速 switches/makes 另一个 window 活跃的东西。

我尝试了下面的代码,但它没有像它所说的那样工作 object has no attribute 'focus'

import pygetwindow as gw

win = gw.getWindowsWithTitle('Photoshop')[0]
win.focus()

我正在使用 Windows 8

我认为您要的对象方法是 activate:

>>> help(win.activate)
Help on method activate in module 
pygetwindow._pygetwindow_win:

activate() method of 
pygetwindow._pygetwindow_win.Win32Window instance
    Activate this window and make it the foreground window.

因此,按如下方式更改代码应该可行。

import pygetwindow as gw

win = gw.getWindowsWithTitle('Photoshop')[0]
win.activate()