错误
pywintypes.error: (0, 'SetForegroundWindow', 'No error message is available')
pywintypes.error: (5, 'SetForegroundWindow', '拒绝访问。')
解决方法
SetForegroundWindow
调用有一些限制,我们可以再调用之前输入一个键盘事件
import win32gui, win32com.client
shell = win32com.client.Dispatch("WScript.Shell")
shell.SendKeys('%')
win32gui.SetForegroundWindow(window)