| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- import win32clipboard as w
- import win32con
- import win32api
- import win32gui
- import time
- # 把文字放入剪贴板
- def setText(aString):
- w.OpenClipboard()
- w.EmptyClipboard()
- w.SetClipboardData(win32con.CF_UNICODETEXT, aString)
- w.CloseClipboard()
- # 模拟ctrl+V
- def ctrlV():
- win32api.keybd_event(17, 0, 0, 0) # 按下ctrl
- win32api.keybd_event(86, 0, 0, 0) # 按下V
- win32api.keybd_event(86, 0, win32con.KEYEVENTF_KEYUP, 0) # 释放V
- win32api.keybd_event(17, 0, win32con.KEYEVENTF_KEYUP, 0) # 释放ctrl
- # 模拟alt+s
- def altS():
- win32api.keybd_event(18, 0, 0, 0)
- win32api.keybd_event(83, 0, 0, 0)
- win32api.keybd_event(83, 0, win32con.KEYEVENTF_KEYUP, 0)
- win32api.keybd_event(18, 0, win32con.KEYEVENTF_KEYUP, 0)
- # 模拟enter
- def enter():
- win32api.keybd_event(13, 0, 0, 0)
- win32api.keybd_event(13, 0, win32con.KEYEVENTF_KEYUP, 0)
- # 模拟鼠标单击
- def click():
- win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)
- win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)
- # 移动鼠标的位置
- def movePos(x, y):
- win32api.SetCursorPos((x, y))
- if __name__ == "__main__":
- hwnd = win32gui.FindWindow("WeWorkWindow", '企业微信') # 返回微信窗口的句柄信息
- win32gui.ShowWindow(hwnd, win32con.SW_SHOW) # 激活并显示微信窗口
- win32gui.MoveWindow(hwnd, 0, 0, 1000, 700, True) # 将微信窗口移动到指定位置和大小
- movePos(30, 90)
- click()
- movePos(110, 40)
- click()
- setText("檀烈")
- ctrlV()
- time.sleep(1) # 等待联系人搜索成功
- #enter()
|