教程1的鼠标键盘操作比较原始,有没一些简单一点的封装包?有。
PyUserInput
这个包里面分为pymouse和pykeyboard
使用的话只需要分别import就行了
from pymouse import PyMouse
from pykeyboard import PyKeyboard
m = PyMouse()
k = PyKeyboard()
鼠标操作
点击
def click(self, x, y, button=1, n=1):
"""
Click a mouse button n times on a given x, y.
Button is defined as 1 = left, 2 = right, 3 = middle.
"""
按下
def press(self, x, y, button=1):
"""
Press the mouse on a given x, y and button.
Button is defined as 1 = left, 2 = right, 3 = middle.
"""
放开
def release(self, x, y, button=1):
"""
Release the mouse on a given x, y and button.
Button is defined as 1 = left, 2 = right, 3 = middle.
"""
移动
def move(self, x, y):
"""Move the mouse to a given x and y"""
拖拽(按住移动)
def drag(self, x, y):
"""Drag the mouse to a given x and y.
A Drag is a Move where the mouse key is held down."""
求鼠标坐标
def position(self):
"""
Get the current mouse position in pixels.
Returns a tuple of 2 integers
"""
求屏幕大小
def screen_size(self):
"""
Get the current screen size in pixels.
Returns a tuple of 2 integers
"""
键盘操作
按下
def press_key(self, character=''):
"""
Press a given character key.
"""
松开
def release_key(self, character=''):
"""
Release a given character key.
"""
特殊键
按下和松开
def tap_key(self, character='', n=1, interval=0):
"""Press and release a given character key n times.
interval是操作完成后多久放开指针,不影响当前操作,但是影响它下面的操作什么时候执行。"""
输入字符串
def type_string(self, char_string, interval=0):
"""
A convenience method for typing longer strings of characters. Generates
as few Shift events as possible."""
组合按键
def send_crtl_alt_x(x):
"""
封装crtl_alt+X组合按键
"""
k.press_key(k.control_key)
k.press_key(k.alt_key)
k.tap_key(x)
k.release_key(k.alt_key)
k.release_key(k.control_key)