鱼C论坛

 找回密码
 立即注册
查看: 3810|回复: 2

[技术交流] pykeyboard模块的学习(踩的坑也不浅)

[复制链接]
发表于 2021-3-11 21:21:40 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
  1. import win32gui,win32con,win32api,os,time
  2. from ctypes import *
  3. from pykeyboard import PyKeyboard   # 这个绝对不能pip 而是需要pip pyuserinput
  4.                                     # pyuserinput 之后 千万不要 pip pykeyboard

  5. apppath=r'"C:\Program Files (x86)\UleSoft\邮掌柜4\邮掌柜.exe"'

  6. #os.system(apppath)   #这个system是拥塞式执行,不适合本程序
  7. os.popen(apppath)
  8. hwnd=win32gui.GetForegroundWindow()
  9. xypos=win32gui.GetWindowPlacement(hwnd)[4]
  10. x,y=xypos[0],xypos[1]
  11. hight=xypos[3]-xypos[1]
  12. width=xypos[2]-xypos[0]
  13. pos_x=x+width*0.6
  14. pos_y=y+hight*0.5
  15. time.sleep(1)
  16. windll.user32.SetCursorPos(int(pos_x),int(pos_y))
  17. into=PyKeyboard()
  18. into.type_string("90891023")
  19. win32api.keybd_event(9,0,0,0)   #9 代表TAB
  20. win32api.keybd_event(9,0,win32con.KEYEVENTF_KEYUP,0)
  21. into.type_string("90891023")
  22. win32api.keybd_event(13,0,0,0)   #13 代表回车
  23. win32api.keybd_event(13,0,win32con.KEYEVENTF_KEYUP,0)
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2021-3-14 10:47:25 | 显示全部楼层
  1. import win32gui,win32con,win32api,os,time,win32com
  2. from ctypes import *
  3. from win32com.client import Dispatch, constants
  4. from pykeyboard import PyKeyboard   # 这个绝对不能pip 而是需要pip pyuserinput
  5.                                     # pyuserinput 之后 千万不要 pip pykeyboard

  6. lst=open("yzg.txt","r")
  7. for zh in lst:
  8.     #print(x)
  9.     apppath=r'"C:\Program Files (x86)\UleSoft\邮掌柜4\邮掌柜.exe"'

  10.     #os.system(apppath)   #这个system是拥塞式执行,不适合本程序
  11.     os.popen(apppath)
  12.     time.sleep(1)
  13.     shell = win32com.client.Dispatch("WScript.Shell")
  14.     shell.SendKeys('%')
  15.     win32gui.SetForegroundWindow(win32gui.FindWindow("CefBrowserWindow","邮掌柜"))
  16.     hwnd=win32gui.GetForegroundWindow()
  17.     xypos=win32gui.GetWindowPlacement(hwnd)[4]
  18.     x,y=xypos[0],xypos[1]
  19.     hight=xypos[3]-xypos[1]
  20.     width=xypos[2]-xypos[0]
  21.     pos_x=x+width*0.754
  22.     pos_y=y+hight*0.426
  23.     #print(pos_x,pos_y)
  24.     time.sleep(1)
  25.     windll.user32.SetCursorPos(int(pos_x),int(pos_y))
  26.     win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)
  27.     win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)
  28.     into=PyKeyboard()
  29.     into.tap_key(into.backspace_key,n=10,interval=0.1)
  30.     into.type_string(zh)
  31.     win32api.keybd_event(9,0,0,0)   #9 代表TAB
  32.     win32api.keybd_event(9,0,win32con.KEYEVENTF_KEYUP,0)
  33.     into.type_string(zh)
  34.     win32api.keybd_event(13,0,0,0)   #13 代表回车
  35.     win32api.keybd_event(13,0,win32con.KEYEVENTF_KEYUP,0)
  36.     #break
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2021-3-24 15:36:38 | 显示全部楼层
  1. import win32gui,win32con,win32api,os,time,win32com
  2. from ctypes import *
  3. from win32com.client import Dispatch, constants
  4. from pykeyboard import PyKeyboard # 这个绝对不能pip 而是需要pip pyuserinput
  5. # pyuserinput 之后 千万不要 pip pykeyboard

  6. #lst=open("yzg.txt","r")
  7. #for zh in lst:
  8. zh="69003004"
  9. #print(x)
  10. apppath=r'"C:\Program Files (x86)\UleSoft\邮掌柜4\邮掌柜.exe"'
  11. apppath=r'"E:\360SoftMgrGame\邮掌柜4\邮掌柜.exe"'
  12. #os.system(apppath) #这个system是拥塞式执行,不适合本程序
  13. os.popen(apppath)
  14. time.sleep(1)
  15. shell = win32com.client.Dispatch("WScript.Shell")
  16. shell.SendKeys('%')
  17. win32gui.SetForegroundWindow(win32gui.FindWindow("CefBrowserWindow","邮掌柜"))
  18. hwnd=win32gui.GetForegroundWindow()
  19. xypos=win32gui.GetWindowPlacement(hwnd)[4]
  20. x,y=xypos[0],xypos[1]
  21. hight=xypos[3]-xypos[1]
  22. width=xypos[2]-xypos[0]
  23. pos_x=x+width*0.70
  24. pos_y=y+hight*0.455
  25. #print(pos_x,pos_y)
  26. time.sleep(1)
  27. windll.user32.SetCursorPos(int(pos_x),int(pos_y))
  28. win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)
  29. win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)
  30. into=PyKeyboard()
  31. into.tap_key(into.backspace_key,n=10,interval=0.1)
  32. into.type_string(zh)
  33. time.sleep(1)
  34. win32api.keybd_event(9,0,0,0) #9 代表TAB
  35. win32api.keybd_event(9,0,win32con.KEYEVENTF_KEYUP,0)
  36. into.type_string(zh)
  37. time.sleep(1)
  38. win32api.keybd_event(13,0,0,0) #13 代表回车
  39. win32api.keybd_event(13,0,win32con.KEYEVENTF_KEYUP,0)
  40. time.sleep(3)
  41. win32api.keybd_event(18,0,0,0) #115 代表ALT
  42. win32api.keybd_event(115,0,0,0) #115 代表F4
  43. win32api.keybd_event(115,0,win32con.KEYEVENTF_KEYUP,0)
  44. win32api.keybd_event(18,0,win32con.KEYEVENTF_KEYUP,0)
  45. time.sleep(2)
  46. win32api.keybd_event(13,0,0,0) #13 代表回车
  47. win32api.keybd_event(13,0,win32con.KEYEVENTF_KEYUP,0)
  48. #break
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-6-6 03:45

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表