只用20行Python代碼實(shí)現(xiàn)屏幕錄制功能
一、模塊安裝
首先,我們需要用到兩個(gè)python的兩個(gè)模塊,win32gui和PyQt5
1.pip install win32gui
2.pip install PyQt5
1、pip install win32gui PS C:\Users\lex\Desktop> pip install win32gui Looking in indexes: http://mirrors.aliyun.com/pypi/simple Requirement 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 PyQt5 PS C:\Users\lex\Desktop> pip install PyQt5 Looking in indexes: http://mirrors.aliyun.com/pypi/simple Requirement 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>
二、設(shè)計(jì)思路
1.通過(guò)win32gui模塊,調(diào)用windows系統(tǒng)的截屏功能,對(duì)屏幕進(jìn)行錄制。
2.通過(guò)timer定時(shí)器,實(shí)現(xiàn)每隔2秒鐘,截屏一次,從而記錄屏幕使用者的操作記錄。
3.對(duì)截取的屏幕按照 截取時(shí)間進(jìn)行命名,并存儲(chǔ)到一個(gè)比較隱秘的文件夾路徑中。
這樣,我們通過(guò),查看文件夾中的照片,就可以清晰的掌握 不明登陸者,在電腦上進(jìn)行了什么樣的操作。
三、代碼實(shí)現(xiàn)
只需要簡(jiǎn)簡(jiǎn)單單10多行代碼,就可以實(shí)現(xiàn)對(duì)windows系統(tǒng)電腦屏幕的錄制。
代碼如下:
#定義函數(shù),每個(gè)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)
四、運(yùn)行方法
1.python環(huán)境檢查
命令行運(yùn)行 python,查看python版本為3.6.5
PS C:\Users\lex\Desktop> python Python 3.6.5 (v3.6.5:f59c0932b4, Mar 28 2018, 17:00:18) [MSC v.1900 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>>
2.程序運(yùn)行
命令行運(yùn)行 python py-screen.py 即可,效果如下圖:

五、完整代碼
from PyQt5.QtWidgets import QApplication
import win32gui
import sys
import time
record = 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)
六、故事結(jié)尾
最后,看了一下電腦截圖
原來(lái)只是在直播而已

還好還好,python小哥哥終于可以放心的睡了
到此這篇關(guān)于只用20行Python代碼實(shí)現(xiàn)屏幕錄制功能的文章就介紹到這了,更多相關(guān)Python屏幕錄制內(nèi)容請(qǐng)搜索本站以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持本站!
版權(quán)聲明:本站文章來(lái)源標(biāo)注為YINGSOO的內(nèi)容版權(quán)均為本站所有,歡迎引用、轉(zhuǎn)載,請(qǐng)保持原文完整并注明來(lái)源及原文鏈接。禁止復(fù)制或仿造本網(wǎng)站,禁止在非maisonbaluchon.cn所屬的服務(wù)器上建立鏡像,否則將依法追究法律責(zé)任。本站部分內(nèi)容來(lái)源于網(wǎng)友推薦、互聯(lián)網(wǎng)收集整理而來(lái),僅供學(xué)習(xí)參考,不代表本站立場(chǎng),如有內(nèi)容涉嫌侵權(quán),請(qǐng)聯(lián)系alex-e#qq.com處理。
關(guān)注官方微信