Python控制鼠标键盘代码实例
作者:GZH媛程序 时间:2021-07-28 11:17:30
python控制鼠标键盘其实很容易,我们在写程序的时候很多时候会用的到!
python控制鼠标键盘步骤及代码
1、安装类库
pip install pyautogui
2、代码:
import pyautogui,time,random
pyautogui.PAUSE = 3
pyautogui.FAILSAFE = True
width, height = pyautogui.size()
#print(str(width))
#print(str(height))
def drawRct():
for i in range(10):
pyautogui.moveTo(300, 300, duration=0.25)
pyautogui.moveTo(400, 300, duration=0.25)
pyautogui.moveTo(400, 400, duration=0.25)
pyautogui.moveTo(300, 400, duration=0.25)
def mouseScroll():
time.sleep(5)
for i in range(10):
pyautogui.scroll(-200)
time.sleep(2)
def getXy():
try:
while True:
x, y = pyautogui.position()
print(x,y)
except KeyboardInterrupt:
print('\nExit.')
def playVideo(x,y):
for i in range(4):
pyautogui.click(x,y)
x=x+240
playAndComment()
def playAndComment():
time.sleep(random.randint(5,15))
pyautogui.scroll(-400)
pyautogui.scroll(-400)
pyautogui.click(200,300)
pyautogui.typewrite('very good!')
pyautogui.click(900,400)
pyautogui.click(710,16)
if __name__ == '__main__':
time.sleep(5)
pyautogui.scroll(-300)
for i in range(9):
print(str(i))
time.sleep(random.randint(3,5))
#pyautogui.click(360,16)
pyautogui.scroll(-300)
time.sleep(random.randint(1,5))
playVideo(404,330)
直接监听用户键盘操作
from pynput.keyboard import Listener
import logging
location = "./"
logging.basicConfig( filename=(location+"keylogger.txt"), format="%(message)s", level=logging.DEBUG)
def press(key):
logging.info(key)
with Listener(on_press = press) as listener:
print('The program begins to watch the action of keyboard:')
listener.join()
来源:https://www.cnblogs.com/ycx1024/p/14055506.html
标签:Python,控制,鼠标,键盘
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
关于Python下载大文件时哪种方式速度更快
2021-03-15 05:46:37
一篇文章带你了解python标准库--datetime模块
2022-08-21 03:42:04
![](https://img.aspxhome.com/file/2023/0/112400_0s.png)
Python中如何替换字典中的值
2022-10-04 21:21:35
Web标准之路 勿使用W3C废弃的元素
2009-07-13 12:25:00
配置高可用性的MySQL服务器负载均衡群集
2009-01-04 12:43:00
Python 人工智能老照片修复算法学习
2022-10-31 03:37:18
![](https://img.aspxhome.com/file/2023/2/113172_0s.jpg)
python中not not x 与bool(x) 的区别
2021-04-27 03:50:17
![](https://img.aspxhome.com/file/2023/1/120371_0s.png)
php获取文章内容第一张图片的方法示例
2023-11-09 18:55:14
Python 可视化matplotlib模块基础知识
2021-09-09 05:17:45
![](https://img.aspxhome.com/file/2023/1/117351_0s.png)
Python简单生成随机姓名的方法示例
2023-04-26 19:35:58
![](https://img.aspxhome.com/file/2023/0/112180_0s.png)
python写入xml文件的方法
2023-01-01 15:08:54
pandas实战:分析三国志人物示例实现
2023-07-12 21:11:46
![](https://img.aspxhome.com/file/2023/2/103672_0s.png)
Python使用正则表达式获取网页中所需要的信息
2023-04-08 17:13:33
python中用ggplot绘制画图实例讲解
2023-07-04 07:25:16
![](https://img.aspxhome.com/file/2023/1/77041_0s.jpg)
XML简易教程之四
2008-09-05 17:19:00
php购物车实现方法
2023-11-16 22:54:51
Oracle 游标使用总结
2009-10-02 17:36:00
python 进程间数据共享multiProcess.Manger实现解析
2021-03-25 14:06:53
在ASP.NET 2.0中操作数据之四十:自定义DataList编辑界面
2023-07-07 04:45:20
![](https://img.aspxhome.com/file/2023/0/75550_0s.png)
Python3.5面向对象编程图文与实例详解
2023-12-04 23:21:51
![](https://img.aspxhome.com/file/2023/8/88008_0s.png)