从python中的函数调用键盘记录器将进入无响应状态
我有一个python文件从python中的函数调用键盘记录器将进入无响应状态,python,issue-tracking,keylogger,Python,Issue Tracking,Keylogger,我有一个python文件GUIApp.py,它创建了一个基于TkinterGUI的窗口,现在单击submit我想keylogger在后台启动并运行,记录输入的键。当我尝试调用键盘记录器功能时,Tkinter窗口将关闭 恢复为非响应状态,不执行其余操作。下面是代码。请帮忙 从tkinter导入* 导入pynput 导入日志记录 从pynput.keyboard导入键作为键,侦听器 def typingActivity(): 键=[] log_dir=r“C:/Users/navesh/deskto
GUIApp.py
,它创建了一个基于Tkinter
GUI的窗口,现在单击submit我想keylogger
在后台启动并运行,记录输入的键。当我尝试调用键盘记录器
功能时,Tkinter
窗口将关闭
恢复为非响应状态,不执行其余操作。下面是代码。请帮忙
从tkinter导入*
导入pynput
导入日志记录
从pynput.keyboard导入键作为键,侦听器
def typingActivity():
键=[]
log_dir=r“C:/Users/navesh/desktop/”
logging.basicConfig(文件名=(log_dir+“kLog.txt”),级别=logging.INFO,格式='(asctime)s:%(消息)s')
def on_按(键):
key.append(key)
#写入文件(密钥)
logging.info(“按下”+str(键))
def on_释放(钥匙):
#打印({0}已发布。格式(键))
key.append(key)
logging.info(“已发布”+str(键))
有监听器(按上=按上,
on_release=on_release)作为侦听器:
listener.join()
typingAct=Tk()
打字作业标题(“打字作业”)
键入计算几何体(“1500x1500”)
userId=userTextbox.get()
q1Label=标签(键入Act,text=“1.您为什么推荐这款手机”)
Q1标签包()
q1Textbox=输入(键入ct,宽度=90)
q1Textbox.pack()
log_dir=r“C:/Users/desktop/”
logging.basicConfig(文件名=(log_dir+userId+“.txt”),级别=logging.INFO,格式='%(asctime)s:%(message)s')
root=Tk()
root.title(“数据收集”)
根几何(“1000x1000”)
welcomeText=文本(根,高度=20,宽度=50)
#welcomeText.configure('bold_italics',font=('Arial',12',bold',italic'))
#root,text=“在桌面中打开浏览器”)
welcomeText.pack()
welcomeText.插入(结束,“欢迎”)
userLabel=Label(root,text=“输入UserID”)
userLabel.pack()
userTextbox=条目(根,宽度=30)
userTextbox.pack()`在此处输入代码`
submitButton=按钮(root,text=“Next”,command=typingActivity)
submitButton.pack()
root.mainloop()
创建两个脚本,一个是GUI,另一个是键盘记录器脚本:
#GUI.py
import tkinter as tk
import os
import time
import pytesseract_capturer
top = tk.Tk()
top.geometry("200x50")
def opening():
os.system("keylogger.py") #this runs the script keylogger.py when you click capture(or mention the location where your keylogger is)
b = tk.Button(top,text = "quit",width=10, fg="red", command=quit)
b.pack(side=tk.RIGHT)
a = tk.Button(top,text = "capture",width=10, fg="blue", command=opening)
a.pack(side=tk.LEFT)
top.mainloop()
键盘记录器.py
# keylogger using pynput module
import pynput
from pynput.keyboard import Key, Listener
keys = []
def on_press(key):
keys.append(key)
write_file(keys)
try:
print('alphanumeric key {0} pressed'.format(key.char))
except AttributeError:
print('special key {0} pressed'.format(key))
def write_file(keys):
with open('D:/log.txt', 'w') as f: # This will save in D drive as log.txt
for key in keys:
# removing ''
k = str(key).replace("'", "")
f.write(k)
# explicitly adding a space after
# every keystroke for readability
f.write(' ')
def on_release(key):
print('{0} released'.format(key))
if key == Key.esc:
# Stop listener
return False
with Listener(on_press = on_press,
on_release = on_release) as listener:
listener.join()
我试过你给我的密码。这也只是创建了一个没有响应的窗口。在我指定的代码中单击Next,我需要做两件事。1.调用键盘记录器2。打开另一个窗口。但是,对于您的代码,第二个窗口也不会被调用,而且第一个带有“下一步”按钮的窗口也会变为不响应状态尝试等待几次,大约一分钟,或者打开任务管理器,查看它是否正在使用cpu或ram,或者值是否正在更改,如果是,则等待一段时间