这篇教程只用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常用函数详解 |