wework_test.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import win32clipboard as w
  2. import win32con
  3. import win32api
  4. import win32gui
  5. import time
  6. # 把文字放入剪贴板
  7. def setText(aString):
  8. w.OpenClipboard()
  9. w.EmptyClipboard()
  10. w.SetClipboardData(win32con.CF_UNICODETEXT, aString)
  11. w.CloseClipboard()
  12. # 模拟ctrl+V
  13. def ctrlV():
  14. win32api.keybd_event(17, 0, 0, 0) # 按下ctrl
  15. win32api.keybd_event(86, 0, 0, 0) # 按下V
  16. win32api.keybd_event(86, 0, win32con.KEYEVENTF_KEYUP, 0) # 释放V
  17. win32api.keybd_event(17, 0, win32con.KEYEVENTF_KEYUP, 0) # 释放ctrl
  18. # 模拟alt+s
  19. def altS():
  20. win32api.keybd_event(18, 0, 0, 0)
  21. win32api.keybd_event(83, 0, 0, 0)
  22. win32api.keybd_event(83, 0, win32con.KEYEVENTF_KEYUP, 0)
  23. win32api.keybd_event(18, 0, win32con.KEYEVENTF_KEYUP, 0)
  24. # 模拟enter
  25. def enter():
  26. win32api.keybd_event(13, 0, 0, 0)
  27. win32api.keybd_event(13, 0, win32con.KEYEVENTF_KEYUP, 0)
  28. # 模拟鼠标单击
  29. def click():
  30. win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)
  31. win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)
  32. # 移动鼠标的位置
  33. def movePos(x, y):
  34. win32api.SetCursorPos((x, y))
  35. if __name__ == "__main__":
  36. hwnd = win32gui.FindWindow("WeWorkWindow", '企业微信') # 返回微信窗口的句柄信息
  37. win32gui.ShowWindow(hwnd, win32con.SW_SHOW) # 激活并显示微信窗口
  38. win32gui.MoveWindow(hwnd, 0, 0, 1000, 700, True) # 将微信窗口移动到指定位置和大小
  39. movePos(30, 90)
  40. click()
  41. movePos(110, 40)
  42. click()
  43. setText("檀烈")
  44. ctrlV()
  45. time.sleep(1) # 等待联系人搜索成功
  46. #enter()