首页 > 编程语言 > 详细

Python包介绍

时间:2020-05-26 14:23:47      阅读:50      评论:0      收藏:0      [点我收藏+]

PyAutoGui -- 模拟操控鼠标键盘

鼠标位置实时获取

import os
import time
import pyautogui as pag 
try:
    while True:
        print("Press Ctrl-C to end")
        screenwidth,screenheight = pag.size()
        print(screenwidth,screenheight)
        x,y = pag.position()
        posstr = "Position:" + str(x).rjust(4)+‘,‘+str(y).rjust(4)
        print(posstr)
        time.sleep(0.2)
        os.system(‘cls‘)
except KeyboardInterrupt:
    print("end......")

详细方法

1、安全设置
  • 保护措施,避免失控
    pyautogui.FAILSAFE = true

  • 为所有的PyAutoGUI函数增加延迟。默认延迟时间是0.1秒
    pyautogui.PAUSE = 0.5

  • True=>确定x,y在屏幕上
    print(pyautogui.onScreen(0, 0))

  • Size(width=1920, height=1080)=>确定屏幕尺寸
    print(pyautogui.size())

2、移动鼠标
  • 绝对移动
    pyautogui.moveTo(100, 200)

  • 相对移动
    pyautogui.moveRel(100, 200)

  • 绝对拖拽鼠标
    pyautogui.dragTo(100, 200, button=‘left‘)

  • 相对拖拽鼠标
    pyautogui.dragRel(30, 0, 2, button=‘right‘)

  • 鼠标双击--leftClic、rightClick、middleClick、tripleClick
    pyautogui.click(x=100, y=200, clicks=2, button=pyautogui.LEFT)
    pyautogui.doubleClick(x=100, y=200, button=pyautogui.LEFT)

  • 鼠标移动到(100,200),向上滚10次,点击
    pyautogui.scroll(10, x=100, y=100)

  • 鼠标按下和抬起
    pyautogui.mouseDown()
    pyautogui.mouseUp()

3、键盘输入
  • 输入字符
    pyautogui.typewrite(‘Hello world!‘)

  • 按下键,抬起键和press(可以传列表)

pyautogui.keyDown(‘shift‘)  -- hold down the shift key
pyautogui.press(‘left‘)  -- press the left arrow key
pyautogui.press(‘left‘)  -- press the left arrow key
pyautogui.press(‘left‘)  -- press the left arrow key
pyautogui.keyUp(‘shift‘)  -- release the shift key
  • 组合热键
    pyautogui.hotkey(‘ctrl‘, ‘a‘)
    pyautogui.hotkey(‘ctrl‘, ‘c‘)

其他

1、提示信息
  • 提示窗口
    pyautogui.alert(text=‘This is an alert box.‘, title=‘Test‘)

  • 选择窗口
    a = pyautogui.confirm(‘Enter option.‘, buttons=[‘A‘, ‘B‘, ‘C‘])

  • 密码输入窗口
    a = pyautogui.password(‘Enter password (text will be hidden)‘)

  • 文本输入窗口
    a = pyautogui.prompt(‘input message‘)

Python包介绍

原文:https://www.cnblogs.com/lixxxx/p/12964897.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!