目錄
- 一、模塊安裝
- 二、設(shè)計(jì)思路
- 三、代碼實(shí)現(xiàn)
- 四、運(yùn)行方法
- 五、完整代碼
- 六、故事結(jié)尾
一、模塊安裝
首先,我們需要用到兩個(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-sip13,>=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.通過win32gui模塊,調(diào)用windows系統(tǒng)的截屏功能,對(duì)屏幕進(jìn)行錄制。
2.通過timer定時(shí)器,實(shí)現(xiàn)每隔2秒鐘,截屏一次,從而記錄屏幕使用者的操作記錄。
3.對(duì)截取的屏幕按照 截取時(shí)間進(jìn)行命名,并存儲(chǔ)到一個(gè)比較隱秘的文件夾路徑中。
這樣,我們通過,查看文件夾中的照片,就可以清晰的掌握 不明登陸者,在電腦上進(jìn)行了什么樣的操作。
三、代碼實(shí)現(xià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é)尾
最后,看了一下電腦截圖
原來只是在直播而已
還好還好,python小哥哥終于可以放心的睡了
到此這篇關(guān)于只用20行Python代碼實(shí)現(xiàn)屏幕錄制功能的文章就介紹到這了,更多相關(guān)Python屏幕錄制內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
您可能感興趣的文章:- 給大家整理了19個(gè)pythonic的編程習(xí)慣(小結(jié))
- Python入門篇之編程習(xí)慣與特點(diǎn)
- 符合語言習(xí)慣的 Python 優(yōu)雅編程技巧【推薦】
- Python一行代碼實(shí)現(xiàn)自動(dòng)發(fā)郵件功能
- 只需要100行Python代碼就可以實(shí)現(xiàn)的貪吃蛇小游戲
- 利用Python計(jì)算圓周率π的實(shí)例代碼
- 寫好Python代碼的幾條重要技巧
- Python 線程池模塊之多線程操作代碼
- python使用tkinter實(shí)現(xiàn)透明窗體上繪制隨機(jī)出現(xiàn)的小球(實(shí)例代碼)
- python3調(diào)用c語言代碼的全過程記錄
- Python代碼風(fēng)格與編程習(xí)慣重要嗎?