首先,我們需要用到兩個python的兩個模塊,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>
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> 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.程序運行
命令行運行 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)
最后,看了一下電腦截圖
原來只是在直播而已
還好還好,python小哥哥終于可以放心的睡了
到此這篇關于只用20行Python代碼實現屏幕錄制功能的文章就介紹到這了,更多相關Python屏幕錄制內容請搜索腳本之家以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持腳本之家!