getHandler.py 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import win32gui,win32api,win32con
  2. import time
  3. # 获取user32.dll的API
  4. from ctypes import windll
  5. def test():
  6. time.sleep(5)
  7. user32 = windll.user32
  8. # 获取当前窗口句柄
  9. hwnd = user32.GetForegroundWindow()
  10. # 获取句柄对应的应用程序
  11. app = win32gui.GetWindowText(hwnd)
  12. print(hwnd)
  13. print(app)
  14. def get_child_windows(parent):
  15. '''
  16. 获得parent的所有子窗口句柄
  17. 返回子窗口句柄列表
  18. '''
  19. if not parent:
  20. return
  21. hwndChildList = []
  22. win32gui.EnumChildWindows(parent, lambda hwnd, param: param.append(hwnd), hwndChildList)
  23. print("hwndChildList=",hwndChildList)
  24. return hwndChildList
  25. def saveChange():
  26. # ctrl+s
  27. win32api.keybd_event(0x11,0,0,0)
  28. win32api.keybd_event(83,0,0,0)
  29. win32api.keybd_event(83,0,win32con.KEYEVENTF_KEYUP,0)
  30. win32api.keybd_event(0x11,0,win32con.KEYEVENTF_KEYUP,0)
  31. def backToOrigin():
  32. # ctrl+z
  33. win32api.keybd_event(0x11,0,0,0)
  34. win32api.keybd_event(90,0,0,0)
  35. win32api.keybd_event(90,0,win32con.KEYEVENTF_KEYUP,0)
  36. win32api.keybd_event(0x11,0,win32con.KEYEVENTF_KEYUP,0)
  37. def closeSubWin():
  38. pass