-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinput_logger.py
69 lines (61 loc) · 1.87 KB
/
input_logger.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 pythoncom
import pyHook
import os
import sendatalogging as log
# create logging file
if not os.path.exists("data"):
os.makedirs("data")
logger = log.Logger("data\\")
logger.writeRow(['Timestamp, ms', 'Event', 'Key value', 'Cursor X, px', 'Cursor Y, px'])
logger.release()
mouse_coordinates = [0,0]
def OnKeyboardEvent(event):
global mouse_coordinates
logger.open()
print 'MessageName:', event.MessageName
print 'Key:', event.Key
print 'Time:', event.Time
# print 'Message:', event.Message
#print 'Window:', event.Window
#print 'WindowName:', event.WindowName
#print 'Ascii:', event.Ascii, chr(event.Ascii)gffd
#print 'KeyID:', event.KeyID
#print 'ScanCode:', event.ScanCode
#print 'Extended:', event.Extended
#print 'Injected:', event.Injected
#print 'Alt', event.Alt
#print 'Transition', event.Transition
print '---'
logger.writeRow([event.Time, "'Key'", "'"+event.Key+"'", mouse_coordinates[0], mouse_coordinates[1]])
logger.release()
# return True to pass the event to other handlers
return True
# Define event callbacks
def OnMouseClickEvent(event):
logger.open()
# called when mouse events are received
print 'MessageName:', event.MessageName
print 'Time:', event.Time
print 'Position:', event.Position
print '---'
logger.writeRow([event.Time, "'Mouse'", "'LDown'", event.Position[0], event.Position[1]])
logger.release()
return True
def OnMouseMoveEvent(event):
print('Move')
global mouse_coordinates
print(event.Position)
mouse_coordinates = list(event.Position)
return True
# create a hook manager
hm = pyHook.HookManager()
# watch for all mouse events
hm.KeyDown = OnKeyboardEvent
hm.MouseAllButtonsDown = OnMouseClickEvent
hm.MouseMove = OnMouseMoveEvent
# set the hook
hm.HookMouse()
hm.HookKeyboard()
# wait forever
pythoncom.PumpMessages()
#