Create a Keylogger with Python – Tutorial

Learn how to create a keylogger for windows using Python. Get user keypresses and store them in a text file. This keyboard logging tutorial uses the pynput module.

Tutorial from Tech With Tim.
Check out Tim’s channel:

Learn to code for free and get a developer job:

Read hundreds of articles on programming:

And subscribe for new videos on technology every day:

source – For all your website needs, visit Spalding Web Design


  1. im not to sure what i did wrong, i get the msg line 1, in <module>
    import pynput
    ModuleNotFoundError: No module named 'pynput' even tho ive installed pynput, please help me ill also really new so please no hate lmao

  2. the first step is to install pynput ?
    The assumption then is that you have Python already installed ….


    Installed PYTHON38
    pip install pynput
    'pip' is not recognized as an internal or external command

    Thanks So much !
    Maybe the Tutorial should start back before you have Python or PIP installed ?

  3. Um excuse me my good sir, firstly super awesome tutorial, when you use the following code

    # with open("log.txt", "a") file:

    "a" in this case has two function it checks if the file exists or not. So in a way it creates the file for you and it starts appending values to it.

  4. hey !! nice video btw!! improved the keylogger but i am stuck at one point!! how to record the shift + some key character like ?,<,{,& etc . I have found to way to record this characters. Help needed . Thanks in advance!!

  5. Hey guys some help if you wouldnt mind, i cant get the write to file loop to start a new line every time i hit space, this is what i have thus far….
    def write_file(keys):

    with open("log.txt", "a") as f:

    for key in keys:

    k = str(key).replace("'"," ")

    if k.find("space") > 0:


    elif k.find("Key") == -1:


  6. i have Anaconda installed as well as PyCharm (I am using PyCharm). I installed pynput through the terminal as you have shown and yet ModuleNotFoundError: No module named 'pynput' still keeps appearing. Help? Thanks!

Leave a comment