使用pymouse,win32api,win32con库,包括windows库和pyHook库,可能会有一些问题,但是都能搜到解决方案,最后附我自用的代码及注释文章来源地址https://www.toymoban.com/news/detail-556582.html
import time
import pymouse
import win32api
import win32con
def get_loc(m):
for i in range(99):
a = m.position() #获取当前坐标的位置
time.sleep(1)
print(a)
def ctrlc():
win32api.keybd_event(17,0,0,0)#ctrl键位码是17
win32api.keybd_event(67,0,0,0) #c键位码是67
win32api.keybd_event(67,0,win32con.KEYEVENTF_KEYUP,0) #释放按键
win32api.keybd_event(17,0,win32con.KEYEVENTF_KEYUP,0)
def ctrlv():
win32api.keybd_event(17,0,0,0) #ctrl键位码是17
win32api.keybd_event(86,0,0,0) #v键位码是86
win32api.keybd_event(86,0,win32con.KEYEVENTF_KEYUP,0) #释放按键
win32api.keybd_event(17,0,win32con.KEYEVENTF_KEYUP,0)
def ctrla():
win32api.keybd_event(17,0,0,0)#ctrl键位码是17
win32api.keybd_event(65,0,0,0) #a键位码是67
win32api.keybd_event(65,0,win32con.KEYEVENTF_KEYUP,0) #释放按键
win32api.keybd_event(17,0,win32con.KEYEVENTF_KEYUP,0)
def right():
win32api.keybd_event(39,0,0,0)#Right Arrow 键位码是39
win32api.keybd_event(39,0,win32con.KEYEVENTF_KEYUP,0) #释放按键
def delete():
win32api.keybd_event(8,0,0,0)#Backspace键位码是39
win32api.keybd_event(8,0,win32con.KEYEVENTF_KEYUP,0) #释放按键
def input_num(i):
win32api.keybd_event(i+96,0,0,0)#单个数字
win32api.keybd_event(i+96,0,win32con.KEYEVENTF_KEYUP,0)
def switchtime(m,x,y):
time.sleep(0.5)
m.click(222,898)#转换时间的位置
time.sleep(0.5)
m.click(222,898)
time.sleep(0.5)
delete()
delete()
time.sleep(0.5)
input_num(x)
input_num(y)
time.sleep(1)
m.click(421,1064)#apply
time.sleep(0.5)
def data1(m):
m.click(1334,342)
time.sleep(0.5)
ctrla()
time.sleep(0.5)
ctrlc()
time.sleep(0.5)
m.click(275,389)
time.sleep(0.5)
ctrlv()
time.sleep(0.5)
right()
time.sleep(0.5)
right()
time.sleep(0.5)
right()
time.sleep(0.5)
def data2(m):
m.click(1822,357)
time.sleep(0.5)
ctrla()
time.sleep(0.5)
ctrlc()
time.sleep(0.5)
m.click(743,383)
time.sleep(0.5)
ctrlv()
time.sleep(0.5)
right()
time.sleep(0.5)
right()
time.sleep(0.5)
right()
time.sleep(0.5)
def alterload(m,x):
time.sleep(0.5)
m.click(679, 913)#转换时间的位置
time.sleep(0.5)
m.click(679, 913)
time.sleep(0.5)
delete()
time.sleep(0.5)
input_num(x)
time.sleep(1)
m.click(973, 1067)#apply
time.sleep(0.5)
def run(m):
m.click(1095,618)
time.sleep(8)
def main(m):
time.sleep(10)#十秒准备
for i in range(1,9):
alterload(m,i)
for j in range(1,4):
for k in range(0,9):
switchtime(m,j,k)
run(m)
data1(m)
data2(m)
#按下组合键ctrl+V
# win32api.keybd_event(97,0,0,0) #1键位码是97
# win32api.keybd_event(97,0,win32con.KEYEVENTF_KEYUP,0) #释放按键
# win32api.keybd_event(98,0,0,0) #2键位码是98
# win32api.keybd_event(98,0,win32con.KEYEVENTF_KEYUP,0)
m = pymouse.PyMouse() # 鼠标的实例
main(m)
#get_loc(m)
文章来源:https://www.toymoban.com/news/detail-556582.html
到了这里,关于python模拟鼠标和键盘的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!