PyMous、PyKeyboard简单工具类

十点数据 1年前 ⋅ 3070 阅读
'''
Created on Dec 12, 2019

@author: admin

模拟鼠标、键盘的通用操作

'''
from pymouse import PyMouse
from pykeyboard import PyKeyboard
import pyperclip 
from com.fy.utils.date.DateUtils import Date_Utils
class PyMousePlugs:
def __init__(self):
    self.du = Date_Utils()
    self.pm = PyMouse()
    self.kb = PyKeyboard()        
    self.x_dim, self.y_dim = self.pm.screen_size() #–获得屏幕尺寸

#向输入框中输入内容,解决了汉字无法输入的问题;
def input(self, kw):
    pyperclip.copy(kw)#把待写入输入框的内容,添加到剪切板中;
    
    #以下语句模拟键盘点击ctrl+v
    print(self.du.getCurrentTimeStr()[11:] + "    模拟键盘点击ctrl+v\n")
    self.kb.press_key(self.kb.control_key)
    self.kb.tap_key('v')
    self.kb.release_key(self.kb.control_key)

#点击
def click(self, x, y):
    self.pm.click(x, y)#点击

#多功能点击
def clickMulti(self, x:"x轴坐标位置", y:"y轴坐标位置", button:"–1表示左键,2表示点击右键", n:"–点击次数,默认是1次,2表示双击"):
    self.pm.click(x, y, button, n)# –鼠标点击 

#获取鼠标位置
def option(self):
    return self.pm.position()

#回车
def enter(self):
    self.kb.tap_key(self.kb.enter_key)#回车,进行搜索

#选择全部内容;
def selectAll(self):
    self.pmp.kb.press_keys([self.pmp.kb.control_r_key, 'a'])#全选
    
#选择并复制全部内容;
def selectAndCopyAll(self):
    self.selectAll()
    self.pmp.kb.press_keys([self.pmp.kb.control_r_key, 'c'])#复制;

全部评论: 0

    我有话说: