[英]How to make a keylogger which can log chained(combined) key presses like ctrl+x , shift + f10, c+h in python3
How to make a keylogger which can log chained(combined) key presses like ctrl+x,shift + f10, c+h in python 3.I have a basic key logger using pynput如何制作一个键盘记录器,它可以在 python 中记录链式(组合)按键,如 ctrl+x、shift + f10、c+h 3.我有一个使用 pynput 的基本键盘记录器
from pynput.keyboard import Listener
def on_press(key):
print(key)
with Listener(on_press=on_press) as listener:
listener.join()
I also tried one using keyboard module it also didn't work(code vanished).我还尝试了一个使用键盘模块的方法,它也不起作用(代码消失了)。 It doesn't return the chained(combined key presses)它不返回链式(组合按键)
how do i do that我怎么做
my need is to make output look like (and examples)我需要使 output 看起来像(和示例)
key:'ctrl+x'
key:'c+x'
key:'ctrl+shift+f10'
key:'cmd + shift + alt'
It should record all possible ones and i dont want to use pyhook(or pyxhook) because it doesn't work properly(if you have it then you can post though)also I don't want to mention the key combination because there are way too many and I want to get all possible one(even if it doesn't do anything).它应该记录所有可能的,我不想使用 pyhook(或 pyxhook),因为它不能正常工作(如果你有它,那么你可以发布)我也不想提到组合键,因为有办法太多了,我想得到所有可能的(即使它什么也没做)。 Currently looking for only windows but if possible I like it to be cross platform.My os is windows 7 python 3.8.8 Thanks目前只寻找 windows 但如果可能的话我喜欢它是跨平台的。我的操作系统是 windows 7 python 3.8.8 谢谢
To get specific combinations of keys you can register like so:要获得特定的键组合,您可以像这样注册:
from pynput import keyboard
def on_activate_h():
print('<ctrl>+<alt>+h pressed')
def on_activate_i():
print('<ctrl>+<alt>+i pressed')
with keyboard.GlobalHotKeys({
'<ctrl>+<alt>+h': on_activate_h,
'<ctrl>+<alt>+i': on_activate_i}) as h:
h.join()
To log all key presses, you could just create listeners for each key separately, and register them the same way要记录所有按键,您可以分别为每个键创建侦听器,并以相同的方式注册它们
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.