wp231957 发表于 2021-3-11 21:21:40

pykeyboard模块的学习(踩的坑也不浅)

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

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

#os.system(apppath)   #这个system是拥塞式执行,不适合本程序
os.popen(apppath)
hwnd=win32gui.GetForegroundWindow()
xypos=win32gui.GetWindowPlacement(hwnd)
x,y=xypos,xypos
hight=xypos-xypos
width=xypos-xypos
pos_x=x+width*0.6
pos_y=y+hight*0.5
time.sleep(1)
windll.user32.SetCursorPos(int(pos_x),int(pos_y))
into=PyKeyboard()
into.type_string("90891023")
win32api.keybd_event(9,0,0,0)   #9 代表TAB
win32api.keybd_event(9,0,win32con.KEYEVENTF_KEYUP,0)
into.type_string("90891023")
win32api.keybd_event(13,0,0,0)   #13 代表回车
win32api.keybd_event(13,0,win32con.KEYEVENTF_KEYUP,0)

wp231957 发表于 2021-3-14 10:47:25

import win32gui,win32con,win32api,os,time,win32com
from ctypes import *
from win32com.client import Dispatch, constants
from pykeyboard import PyKeyboard   # 这个绝对不能pip 而是需要pip pyuserinput
                                    # pyuserinput 之后 千万不要 pip pykeyboard

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

    #os.system(apppath)   #这个system是拥塞式执行,不适合本程序
    os.popen(apppath)
    time.sleep(1)
    shell = win32com.client.Dispatch("WScript.Shell")
    shell.SendKeys('%')
    win32gui.SetForegroundWindow(win32gui.FindWindow("CefBrowserWindow","邮掌柜"))
    hwnd=win32gui.GetForegroundWindow()
    xypos=win32gui.GetWindowPlacement(hwnd)
    x,y=xypos,xypos
    hight=xypos-xypos
    width=xypos-xypos
    pos_x=x+width*0.754
    pos_y=y+hight*0.426
    #print(pos_x,pos_y)
    time.sleep(1)
    windll.user32.SetCursorPos(int(pos_x),int(pos_y))
    win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)
    win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)
    into=PyKeyboard()
    into.tap_key(into.backspace_key,n=10,interval=0.1)
    into.type_string(zh)
    win32api.keybd_event(9,0,0,0)   #9 代表TAB
    win32api.keybd_event(9,0,win32con.KEYEVENTF_KEYUP,0)
    into.type_string(zh)
    win32api.keybd_event(13,0,0,0)   #13 代表回车
    win32api.keybd_event(13,0,win32con.KEYEVENTF_KEYUP,0)
    #break

wp231957 发表于 2021-3-24 15:36:38

wp231957 发表于 2021-3-14 10:47


import win32gui,win32con,win32api,os,time,win32com
from ctypes import *
from win32com.client import Dispatch, constants
from pykeyboard import PyKeyboard # 这个绝对不能pip 而是需要pip pyuserinput
# pyuserinput 之后 千万不要 pip pykeyboard

#lst=open("yzg.txt","r")
#for zh in lst:
zh="69003004"
#print(x)
apppath=r'"C:\Program Files (x86)\UleSoft\邮掌柜4\邮掌柜.exe"'
apppath=r'"E:\360SoftMgrGame\邮掌柜4\邮掌柜.exe"'
#os.system(apppath) #这个system是拥塞式执行,不适合本程序
os.popen(apppath)
time.sleep(1)
shell = win32com.client.Dispatch("WScript.Shell")
shell.SendKeys('%')
win32gui.SetForegroundWindow(win32gui.FindWindow("CefBrowserWindow","邮掌柜"))
hwnd=win32gui.GetForegroundWindow()
xypos=win32gui.GetWindowPlacement(hwnd)
x,y=xypos,xypos
hight=xypos-xypos
width=xypos-xypos
pos_x=x+width*0.70
pos_y=y+hight*0.455
#print(pos_x,pos_y)
time.sleep(1)
windll.user32.SetCursorPos(int(pos_x),int(pos_y))
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)
into=PyKeyboard()
into.tap_key(into.backspace_key,n=10,interval=0.1)
into.type_string(zh)
time.sleep(1)
win32api.keybd_event(9,0,0,0) #9 代表TAB
win32api.keybd_event(9,0,win32con.KEYEVENTF_KEYUP,0)
into.type_string(zh)
time.sleep(1)
win32api.keybd_event(13,0,0,0) #13 代表回车
win32api.keybd_event(13,0,win32con.KEYEVENTF_KEYUP,0)
time.sleep(3)
win32api.keybd_event(18,0,0,0) #115 代表ALT
win32api.keybd_event(115,0,0,0) #115 代表F4
win32api.keybd_event(115,0,win32con.KEYEVENTF_KEYUP,0)
win32api.keybd_event(18,0,win32con.KEYEVENTF_KEYUP,0)
time.sleep(2)
win32api.keybd_event(13,0,0,0) #13 代表回车
win32api.keybd_event(13,0,win32con.KEYEVENTF_KEYUP,0)
#break
页: [1]
查看完整版本: pykeyboard模块的学习(踩的坑也不浅)