美文网首页
Pyuserinput 基础操作(鼠标键盘模拟)

Pyuserinput 基础操作(鼠标键盘模拟)

作者: 浩Haooooo | 来源:发表于2018-06-11 14:00 被阅读0次

    一、调用

    from pymouse import PyMouse
    from pykeyboard import PyKeyboard
    pym = PyMouse()
    pyk = PyKeyboard()
    

    1.PyMouse的基本方法
    1)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.
      把鼠标移动到x,y坐标处,是一个拖拽动作,不只是移动

    2) move(self, x, y)

    • Move the mouse to a given x and y
      把鼠标移动到x,y

    3)position(self)

    • Get the current mouse position in pixels.
    • Returns a tuple of 2 integers
      得到鼠标的当前位置,并返回坐标x,y

    4)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.
      鼠标按下不松开x,y的坐标点,button表示左右键

    5)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.
      松开指定位置的鼠标

    6)scroll(self, vertical=None, horizontal=None, depth=None)

    • Generates mouse scrolling events in up to three dimensions: vertical,horizontal, and depth (Mac-only). Values for these arguments may be positive or negative numbers (float or int). Refer to the following:
      • Vertical: + Up, - Down
      • Horizontal: + Right, - Left
      • Depth: + Rise (out of display), - Dive (towards display)
        滚动鼠标的滚轮,在三个方向上移动

    7)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.
      鼠标点击

    2.PyKeyboard的基本方法
    1)press_key(self, character='')

    • Press a given character key.

    2)release_key(self, character='')

    • Release a given character key.

    3) press_keys(self, characters=[])

    • Press a given character key.

    4)tap_key(self, character='', n=1, interval=0)

    • Press and release a given character key n times.
    #点击功能键F5
    pyk.tap_key(pyk.function_keys[5])
    #点击小键盘5,6次
    pyk.tap_key(pyk.numpad_keys[5],6)
    #点击回车键
    pyk.tap_key(k.enter_key)
    #联合按键模拟
    #同时按alt+tab键盘
    pyk.press_key(pyk.alt_key)#按住alt键
    pyk.tap_key(pyk.tab_key)#点击tab键
    pyk.release_key(pyk.alt_key)#松开alt键
    

    5)type_string(self, char_string, interval=0)

    • A convenience method for typing longer strings of characters. Generates as few Shift events as possible.

    相关文章

      网友评论

          本文标题:Pyuserinput 基础操作(鼠标键盘模拟)

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