- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我为键盘记录器创建了一个线程,该线程与另一个产生一些声音的线程并行记录(我想捕捉 react 时间)。
不幸的是,尽管我调用了 killKey() 并打印了“invoked killkey()”,但线程从未完成。
我总是从这个线程得到一个 thread.isActive() = true。
class KeyHandler(threading.Thread):
hm = pyHook.HookManager()
def __init__(self):
threading.Thread.__init__(self)
def OnKeyboardCharEvent(self,event):
print 'Key:', event.Key
if event.Key=='E':
...
return True
def killKey(self):
KeyHandler.hm.UnhookKeyboard()
ctypes.windll.user32.PostQuitMessage(0)
print "invoked killkey()"
def run(self):
print "keyHandlerstartetrunning"
KeyHandler.hm.KeyDown = self.OnKeyboardCharEvent
KeyHandler.hm.HookKeyboard()
#print "keyboardhooked"
pythoncom.PumpMessages()
更准确地说,ctypes.windll.user32.PostQuitMessage(0) 什么都不做
我希望使用外部超时来调用 killKey(),以及该线程中的相应 ctypes.windll.user32.PostQuitMessage(0)。
最佳答案
PostQuitMessage 必须从同一个线程发布。为此,您需要引入一个全局变量 STOP_KEY_HANDLER
。如果您想退出,只需从您想要的任何线程设置全局 STOP_KEY_HANDLER = True
,它将在下一次击键时退出。您的 key 处理程序必须在主线程上运行。
STOP_KEY_HANDLER = False
def main():
pass # here do all you want
#bla bla
global STOP_KEY_HANDLER
STOP_KEY_HANDLER = True # This will kill KeyHandler
class KeyHandler:
hm = pyHook.HookManager()
def OnKeyboardCharEvent(self,event):
if STOP_KEY_HANDLER:
self.killKey()
print 'Key:', event.Key
if event.Key=='E':
pass
return True
def killKey(self):
global STOP_KEY_HANDLER
if not STOP_KEY_HANDLER:
STOP_KEY_HANDLER = True
return None
KeyHandler.hm.UnhookKeyboard()
ctypes.windll.user32.PostQuitMessage(0)
print "invoked killkey()"
def _timeout(self):
if self.timeout:
time.sleep(self.timeout)
self.killKey()
def run(self, timeout=False):
print "keyHandlerstartetrunning"
self.timeout = timeout
threading.Thread(target=self._timeout).start()
KeyHandler.hm.KeyDown = self.OnKeyboardCharEvent
KeyHandler.hm.HookKeyboard()
#print "keyboardhooked"
pythoncom.PumpMessages()
k=KeyHandler()
threading.Thread(target=main).start()
k.run(timeout=100) # You can specify the timeout in seconds or you can kill it directly by setting STOP_KEY_HANDLER to True.
关于python - pyHook KeyLogger 线程未完成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23516150/
我可能会编写一个程序来检测恶意(或非恶意)软件,即键盘记录(记录击键以获取信息)。 会使用什么战术? 是否有特定的代码要查找? 我应该搜索某些位置吗? 我更喜欢 Java 或 Perl,因为我精通这些
我为键盘记录器创建了一个线程,该线程与另一个产生一些声音的线程并行记录(我想捕捉 react 时间)。 不幸的是,尽管我调用了 killKey() 并打印了“invoked killkey()”,但线
进程文件: keylogger or keylogger.exe 进程名称: JanNet Keylogger 进程类别:存在安全风险的进程 英文描述: keylogger.exe is a
关闭。这个问题需要debugging details .它目前不接受答案。 编辑问题以包含 desired behavior, a specific problem or error, and th
关闭。这个问题需要更多 focused .它目前不接受答案。 想要改进这个问题吗? 更新问题,使其只关注一个问题 editing this post . 关闭 7 年前。 Improve this q
我是一名优秀的程序员,十分优秀!