Basically, I am trying to make a keyboard heatmap which shows various colors for frequency of keys and now after exploring libraries like matplotlib and seaborn I am not getting how to make the heatmap on .Png image of a 104 key layout. I have already created a keylogger and am able to record all the keys in a .txt file where normal keys are stored in char form, but special keys are stored in form like Keys.Space, Keys.LCtrl etc. and now I want to plot the frequency of keys on a keyboard heatmap. I dont want to use libraries like tapmap and kbhmap as they just take .txt file as input and return png of keyboard heatmap but this way I would not be able to show usage of ctrl, shift and backspaces. What should I do?
This is my code for keylogger.
from pynput.keyboard import Key
from pynput.keyboard import Listener
the_keys = []
def functionPerKey(key):
the_keys.append(key)
storeKeysToFile(the_keys)
def storeKeysToFile(keys):
with open('keylog.txt', 'w') as log:
for the_key in keys:
the_key = str(the_key).replace("'", "")
log.write(the_key+'\n')
def onEachKeyRelease(the_key):
if the_key == Key.esc:
return False
with Listener(
on_press = functionPerKey,
on_release = onEachKeyRelease
) as the_listener:
the_listener.join()```
You can use keyboardlayout to display a keyboard and matplotlib.cm.ScalarMappable to map colors to keystroke counts (assuming you already have a counter of keystrokes):
Output (keystrokes are fully randomized in my case so this map isn't realistic at all):