0

my code:

f = open("log.txt", "a")
key = chr(event.Ascii)
f.write(key)
f.closed

If I print the key out. I get a nice readable form like "a" "b" "c" and so on. But i if look into the file python has saved it as ascii - like that: 0013 0200 4461

I tried to convert it but i just get errors. Anybody knows whats wrong here?

Samantha
  • 383
  • 1
  • 2
  • 12

1 Answers1

0

I think you need f.close() not f.closed.

Also, you are putting the key code in key.

If you want to read a single char, you could use:

sys.stdin.read(1)

(See: https://stackoverflow.com/a/510404/103081)

Putting it all together:

import sys
f = open("log.txt", "a")
key = sys.stdin.read(1)
f.write(key)
f.close()

This should be fine for a homework problem or learning python on your own. For someone writing a keylogger to steal password and credit card numbers, though, this is useless because return must be hit to get the input.

Community
  • 1
  • 1
Paul
  • 26,170
  • 12
  • 85
  • 119