下载该库
pip install keyboard
键盘log记录的示例链接
https://www.thepythoncode.com/article/write-a-keylogger-python
开发文档里面的示例,我翻译了一下
add_abbreviation()
将输入的文本替换替换为替换为"@email "转化为"test@example.com"
keyboard.add_abbreviation("@email", "test@example.com")
add_hotkey()
键盘钩子,通过监听去回调函数,这里ctrl+space就会去调用f()函数
keyboard.add_hotkey('ctrl+space',f)
is_pressed()
检测按键是否被按下,返回true和false
keyboard.is_pressed('ctrl')
send()
模拟按键操作press_and_release()同理
keyboard.send("windows+d")
#同时按windows+d
keyboard.send("alt+F4, space")
先同时按下alt+F4,然后再按space
press()与release()
长按和释放按键
#按下ctrl
keyboard.press("ctrl")
# 释放ctrl
keyboard.release("ctrl")
write()
write输出文本
keyboard.write("Python Programming is always fun!", delay=0.1)
record()
监听键盘
play()
播放监听这些事件
events = keyboard.record('esc')
#按下esc后停止监听
keyboard.play(events)
模仿输入进行输出
get_typed_strings()
直接输出监听的内容
print(list(keyboard.get_typed_strings(events)))
on_release()
释放按键调用函数
keyboard.on_release(lambda e: print(e.name))
keyboard.unhook_all()
释放所有钩子
keyboard.unhook_all()
本文作者:硝基苯
本文链接:https://www.c6sec.com/index.php/archives/327/
最后修改时间:2021-09-20 20:52:11
本站未注明转载的文章均为原创,并采用 CC BY-NC-SA 4.0 授权协议,转载请注明来源,谢谢!