我尝试了以下操作,但运行脚本时焦点不会返回到具有焦点的程序:
import win32com.client
import win32gui
current = win32gui.GetForegroundWindow()
shell = win32com.client.Dispatch("WScript.Shell")
shell.AppActivate('Console2')
shell.SendKeys('{UP}{ENTER}')
shell.AppActivate(str(current))
Tags:
结果是
win32gui.GetForegroundWindow()
返回的是窗口句柄,而不是进程IDwin32process.GetWindowThreadProcessId(hwnd)
可用于从句柄获取线程ID和进程ID。相关问题 更多 >
编程相关推荐