Python 模拟鼠键

让python 自动操作桌面或应用窗口,点击,滑动鼠标,输入文字等

# coding=utf-8
from pymouse import PyMouse
from pykeyboard import PyKeyboard
import time, random
import pyautogui as pag

m = PyMouse()
k = PyKeyboard()
x_dim, y_dim = m.screen_size()
# 打开浏览器,点击百度搜索框
m.click(282, 183)
time.sleep(0.3)
# 输入关键字
k.type_string('cnblog')
# 回车
k.tap_key(k.enter_key)
# 在页面内瞎点
while True:
    i = random.uniform(-10, 10)
    m.scroll(2 * i, None, None)
    time.sleep(2)
    m.click(500 + 50 * i, 400 + 20 * i)


# 获取鼠标坐标
def getM_xy():
    try:
        while True:
            print "Press Ctrl-C to end"
            x, y = pag.position()  # 返回鼠标的坐标
            posStr = "Position:" + str(x).rjust(4) + ',' + str(y).rjust(4)
            print posStr  # 打印坐标
            time.sleep(1)
            # os.system('cls')  # 清楚屏幕
    except  KeyboardInterrupt:
        print 'end....'

 写出来也不觉得有什么用,纯粹是闲的蛋疼吧。

原文地址:https://www.cnblogs.com/lanqie/p/8400578.html