import win32gui,win32api,win32con import time # 获取user32.dll的API from ctypes import windll def test(): time.sleep(5) user32 = windll.user32 # 获取当前窗口句柄 hwnd = user32.GetForegroundWindow() # 获取句柄对应的应用程序 app = win32gui.GetWindowText(hwnd) print(hwnd) print(app) def get_child_windows(parent): ''' 获得parent的所有子窗口句柄 返回子窗口句柄列表 ''' if not parent: return hwndChildList = [] win32gui.EnumChildWindows(parent, lambda hwnd, param: param.append(hwnd), hwndChildList) print("hwndChildList=",hwndChildList) return hwndChildList def saveChange(): # ctrl+s win32api.keybd_event(0x11,0,0,0) win32api.keybd_event(83,0,0,0) win32api.keybd_event(83,0,win32con.KEYEVENTF_KEYUP,0) win32api.keybd_event(0x11,0,win32con.KEYEVENTF_KEYUP,0) def backToOrigin(): # ctrl+z win32api.keybd_event(0x11,0,0,0) win32api.keybd_event(90,0,0,0) win32api.keybd_event(90,0,win32con.KEYEVENTF_KEYUP,0) win32api.keybd_event(0x11,0,win32con.KEYEVENTF_KEYUP,0) def closeSubWin(): pass