-3

I am a complete beginner at coding, but I am trying to write a program that helps me make my keylogger data better readable. I have a keylogger on my device because I want to study my personal typing habits because I want to make a personalized keyboard layout :) As of now, my keylogger gives me something like this:

2022-05-08 07:58:29,149 - 't'
2022-05-08 07:58:29,249 - 'e'
2022-05-08 07:58:29,386 - 'r'
2022-05-08 07:58:29,670 - Key.backspace
2022-05-08 07:58:29,959 - 'l'
2022-05-08 07:58:30,144 - 'l'
2022-05-08 07:58:30,250 - 'e'
2022-05-08 07:58:30,349 - 'r'
2022-05-08 07:58:30,630 - 's'
2022-05-08 07:58:30,958 - Key.shift
2022-05-08 07:58:31,018 - '?'
2022-05-08 07:58:31,234 - Key.space
2022-05-08 07:58:31,494 - Key.shift_r

Now I have sorted out all that stuff like the date and hyphens and stuff using Microsoft Word "Find and Replace" (I don't know how to change the keylogger code so that it leaves the ascii date away so I just went with the current format), but I have the problem that I don't want to have typos in my keylogger data, so when I pressed a backspace, I obviously want my program to delete the last two instances that I've typed in my list...

This is what my code looks like currently:

    sample = (input)
    x= 0

    for x True: 
    if sample(x) == "Key.backspace":
        del sample[x, x-1]
    x = x + 1
        
input('')

But it doesn't seem to work... can somebody please figure out how I can use x as index for my list?

Random Davis
  • 5,623
  • 3
  • 13
  • 24
Jimmy
  • 1
  • 2
    Share a [mre] please. What is `sample = (input)` doing? Did you overwrite the built-in `input()` method with something with the same name? Why? That's not good practice. And what is `del sample[x, x-1]` supposed to do? Delete from position `x` and position `x-1`? That's not how Python syntax works. You have to delete them one at a time or you'll get the error `TypeError: list indices must be integers or slices, not tuple` if you run that code. Deleting items from a list while looping through it has to be done in a specific way: https://stackoverflow.com/q/1207406/6273251 – Random Davis May 10 '22 at 17:27
  • 2
    It's not clear what you are trying to do. If you are using the `input` function for each key press then you have to press enter after each key you enter and you cannot log backspace or ctrl/alt etc. – elbashmubarmeg May 10 '22 at 17:31
  • 'sample = (input)' is something like 'My List = What I Paste'... I did mean the 'input()' function by that, but since it is a list I figured I might as well write it differently (I thought that items of lists have to be put into brackets). 'del sample[x, x-1]' is supposed to be something like "delete the current item and the one before" (I want to delete the "Key.backspace" and what I actually backspaced from my keylog). I can figure out a way for it to do what I want, my biggest issue is just: How do I get my program to check the list from beginning to end? (0 then 1 then 2 then 3...) – Jimmy May 10 '22 at 18:44
  • Sorry to bother you, I don't even know how to mark what is code for you in the comment section... I guess I'll leave the typos as they are and put coding aside for now... – Jimmy May 10 '22 at 18:46
  • Try reading "Learn Python 3 the Hard Way" by Zed Shaw, it's short and easy. That will give you the basics to understand how python works. – rangeseeker May 10 '22 at 19:28
  • Thank you for your recommendation, rangeseeker! Let's see how far it gets me :) – Jimmy May 11 '22 at 14:11

0 Answers0