Home » Python » python – pyinput key is not being called-Exceptionshub

python – pyinput key is not being called-Exceptionshub

Posted by: admin February 24, 2020 Leave a comment


im having trouble with logging the keys in text document it shows everything thing in the console but in the text document the only thing that i manged to get working is the space bar.

my guess is that (import key) is not being called but im calling it with this (elif k.find(“Key”) == -1)

i know that something is wrong from those 2 because pycharm is showing the (key) as grey while the (listener) as white im new to this and i already asked 2 questions but believe me i research about this and i couldn’t find any thing thats why im asking for your help.

here is my code :

import pynput
from pynput.keyboard import Key, Listener

count = 0
keys = []

def on_press(key):
    global keys, count
    count += 1
    print("{0} pressed".format(key))

    if count >= 30:
        count = 0
        keys = []

def write_file(keys):
    with open("keyloger.txt", "w+") as f:
        for key in keys:
            k = str(key)
            if k.find("space") > 0:
        elif k.find("Key") == -1:

with Listener(on_press=on_press) as listener:

i fixed it whit the help of my friend i forgot to put

def on_realease(key):
     print("{0} pressed".format(key))

but now,
it only shows 30 words it dosnt update every 30 words it stops. i want it to keep going for ever and if the program stops before 30 words i want it to still work (right now it only shows the last 30 words that have been typed if you type more then 30 words it dosnt show all the words that have been typed

the loger conole

the keyloger.txt

in other words its buggy and im too green to fix it on my own i need some help 🙂

How to&Answers: