美文网首页工作生活
win操作(2)-简易键盘鼠标操作

win操作(2)-简易键盘鼠标操作

作者: 瓜T_T | 来源:发表于2019-07-03 18:27 被阅读0次

教程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.
        """

特殊键

image.png

按下和松开

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)

相关文章

  • win操作(2)-简易键盘鼠标操作

    教程1的鼠标键盘操作比较原始,有没一些简单一点的封装包?有。PyUserInput这个包里面分为pymouse和p...

  • day11Pythongame应用

    1.pygame事件及鼠标键盘操作 2.简易pygame设计 3.鼠标拖拽图片功能 4.动画效果 5.球球游戏 6...

  • UI自动化 - senlenium中的鼠标和键盘操作

    一、鼠标和键盘操作 1、鼠标操作 1.1 鼠标操作实现方式 selenium提供鼠标操作的方法及步骤需要导入Act...

  • win操作(1)-键盘鼠标输入

    python比较底层的鼠标键盘操作使用win32api包,使用这个包需要win32con配合,后者封装了几乎所有w...

  • python3+selenium实现Web自动化3:鼠标操作和键

    一、Selenium之鼠标操作和键盘操作 1.鼠标事件在webdriver中,鼠标操作的方法封装在 ActionC...

  • 049-python包pyautogui

    一、鼠标键盘 pyautogui官方文档 1、鼠标移动到屏幕正中间示例 2、常用操作 获取屏幕宽高 获取当前鼠标位...

  • Webdriver中键盘和鼠标的一些操作

    Webdriver中,是由Action类,对键盘和鼠标的操作进行管理: 鼠标点击操作 1、左键单击 Actions...

  • 三、selenium操作元素

    1、此库可以操作单击、右击、拖拉、滚动、复制和黏贴等操作,基本分三大类:常规操作、鼠标操作、键盘操作。 常规操作包...

  • EventSystem

    简介 Input IPointerEnterHandler等接口 键盘,鼠标,操作杆 Input GetAxis:...

  • 2019-05-22

    简介 Input IPointerEnterHandler等接口 键盘,鼠标,操作杆 Input GetAxis:...

网友评论

    本文标题:win操作(2)-简易键盘鼠标操作

    本文链接:https://www.haomeiwen.com/subject/xbvchctx.html