-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathKeyboardMoniter
39 lines (34 loc) · 978 Bytes
/
KeyboardMoniter
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/usr/bin/env python3.7
'''
This script basically records your Keyboard press and
output it to a log file.
for costumorize the log file location,
please change the reference of the "OUTPUT" below
'''
OUTPUT = "/home/ken/script/log/Keyboard.log"
from pynput import keyboard
import time
#set the reference of the log file
def on_press(key):
try:
R_key = time.asctime()+" "+'alphanumeric key {0} pressed'.format(
key.char)
except AttributeError:
R_key = time.asctime()+" "+'special key {0} pressed'.format(
key)
print(R_key.split(' ')[-2])
R_key=R_key+"\n"
with open(OUTPUT, 'a') as f:
f.write(R_key)
#def on_release(key):
# print('{0} released'.format(
# key))
# if key == keyboard.Key.esc:
# # Stop listener
# return False
# Collect events until released
with keyboard.Listener(
on_press=on_press,
# on_release=on_release
) as listener:
listener.join()