錯誤
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)