您当前的位置:首页 > IT编程 > python
| C语言 | Java | VB | VC | python | Android | TensorFlow | C++ | oracle | 学术与代码 | cnn卷积神经网络 | gnn | 图像修复 | Keras | 数据集 | Neo4j | 自然语言处理 | 深度学习 | 医学CAD | 医学影像 | 超参数 | pointnet | pytorch | 异常检测 | Transformers | 情感分类 | 知识图谱 |

自学教程:只用20行Python代码实现屏幕录制功能

51自学网 2021-10-30 22:34:37
  python
这篇教程只用20行Python代码实现屏幕录制功能写得很实用,希望能帮到您。

一、模块安装

首先,我们需要用到两个python的两个模块,win32gui和PyQt5

1.pip install win32gui

2.pip install PyQt5

1、pip install win32guiPS C:/Users/lex/Desktop> pip install win32guiLooking in indexes: http://mirrors.aliyun.com/pypi/simpleRequirement already satisfied: win32gui in f:/develop/python36/lib/site-packages (221.6)Requirement already satisfied: win32core in f:/develop/python36/lib/site-packages (from win32gui) (221.36) 2、pip install PyQt5PS C:/Users/lex/Desktop> pip install PyQt5Looking in indexes: http://mirrors.aliyun.com/pypi/simpleRequirement already satisfied: PyQt5 in f:/develop/python36/lib/site-packages (5.15.4)Requirement already satisfied: PyQt5-sip<13,>=12.8 in f:/develop/python36/lib/site-packages (from PyQt5) (12.8.1)Requirement already satisfied: PyQt5-Qt5>=5.15 in f:/develop/python36/lib/site-packages (from PyQt5) (5.15.2)PS C:/Users/lex/Desktop>

二、设计思路

1.通过win32gui模块,调用windows系统的截屏功能,对屏幕进行录制。

2.通过timer定时器,实现每隔2秒钟,截屏一次,从而记录屏幕使用者的操作记录。

3.对截取的屏幕按照 截取时间进行命名,并存储到一个比较隐秘的文件夹路径中。

这样,我们通过,查看文件夹中的照片,就可以清晰的掌握 不明登陆者,在电脑上进行了什么样的操作。

三、代码实现

只需要简简单单10多行代码,就可以实现对windows系统电脑屏幕的录制。

代码如下:

#定义函数,每个2秒 抓取一次屏幕截屏def timer(n):    while True:          dt= time.strftime('%Y-%m-%d %H%M%S',time.localtime())        screen = QApplication.primaryScreen()        img = screen.grabWindow(record).toImage()        img.save("D://images//"+dt+".jpg")        time.sleep(n)if __name__ == "__main__":    timer(2)

四、运行方法

1.python环境检查

命令行运行 python,查看python版本为3.6.5

PS C:/Users/lex/Desktop> pythonPython 3.6.5 (v3.6.5:f59c0932b4, Mar 28 2018, 17:00:18) [MSC v.1900 64 bit (AMD64)] on win32Type "help", "copyright", "credits" or "license" for more information.>>>

2.程序运行

命令行运行 python py-screen.py 即可,效果如下图:

五、完整代码

from PyQt5.QtWidgets import QApplicationimport win32guiimport sysimport timerecord = win32gui.FindWindow(None, 'C:/Windows/system32/cmd.exe')app = QApplication(sys.argv)def timer(n):    while True:          dt= time.strftime('%Y-%m-%d %H%M%S',time.localtime())        screen = QApplication.primaryScreen()        img = screen.grabWindow(record).toImage()        img.save("D://images//"+dt+".jpg")        time.sleep(n)if __name__ == "__main__":    timer(2)

六、故事结尾

最后,看了一下电脑截图

原来只是在直播而已

还好还好,python小哥哥终于可以放心的睡了

到此这篇关于只用20行Python代码实现屏幕录制功能的文章就介绍到这了,更多相关Python屏幕录制内容请搜索51zixue.net以前的文章或继续浏览下面的相关文章希望大家以后多多支持51zixue.net!


TensorFlow中tf.batch_matmul()的用法
上帝为你开了一扇窗之Tkinter常用函数详解
万事OK自学网:51自学网_软件自学网_CAD自学网自学excel、自学PS、自学CAD、自学C语言、自学css3实例,是一个通过网络自主学习工作技能的自学平台,网友喜欢的软件自学网站。