[Python Study Notes]实现对鼠标控制

Posted 刘六六

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[Python Study Notes]实现对鼠标控制相关的知识,希望对你有一定的参考价值。

\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'
>>文件: 鼠标控制.py
>>作者: liu yang
>>邮箱: liuyang0001@outlook.com
>>博客: www.cnblogs.com/liu66blog

\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys, os
import pynput
from pynput.mouse import Controller,Button

# 实例化鼠标控制
mouse = Controller()

# x坐标+100,y坐标+100
mouse.move(100,100)

# 将鼠标移动到固定位置
mouse.position=(1475, 35)

# 读取当前的鼠标位置
position=format(mouse.position)
print(position)

# 右键单击
mouse.click(Button.right,1)

# 左键双击
mouse.click(Button.left,2)

# 单击的另一种实现,先点击后释放
mouse.press(Button.right)
mouse.release(Button.right)

# 鼠标滚动(x,y)  x代表左右移动,y代表上下移动
# X:正值代表从右向左   Y:正值代表向上移动,负值代表向下移动
mouse.scroll(0,-1000)

以上是关于[Python Study Notes]实现对鼠标控制的主要内容,如果未能解决你的问题,请参考以下文章

[Python Study Notes]psutil模块

[Python Study Notes] psutil模块

[Python Study Notes]物体运动检测

[Python Study Notes]电池信息

[Python Study Notes]内存信息

[Python Study Notes]cpu信息