0

在单击当前前景窗口并让它循环并尝试再次将其设置为前景窗口后,我遇到了 SetForegroundWindow 问题。我目前正在使用以下内容进行设置。

    # Selects the inputed window and maximizes it.
    def select_window(self, wnd):
        wgui.SetForegroundWindow(wnd)  # Activate the window
        wgui.ShowWindow(wnd, wcon.SW_MAXIMIZE)  # Maximizes the window

在我调用它之后,它会进行 Windows 虚拟键输入,然后在计时器完成后,它会循环返回以再次设置窗口,以防它不再是焦点。我尝试使用以下内容,但它不适用于我的代码,因为它会为我目前正在做的事情添加额外的输入:

import win32gui, win32com.client
shell = win32com.client.Dispatch("WScript.Shell")
shell.SendKeys('%') # Or something like shell.SendKeys('a')
win32gui.SetForegroundWindow(wnd)

当我在循环时选择另一个窗口时,我收到以下错误消息:

pywintypes.error: (0, 'SetForegroundWindow', 'No error message is available')

所以我在寻找是否有任何替代 SetForegroundWindow 的方法,或者在通过代码的第二次循环调用前台窗口之前必须发送某种密钥的方法。

4

0 回答 0