-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKeylogger.m
More file actions
71 lines (59 loc) · 2.22 KB
/
Keylogger.m
File metadata and controls
71 lines (59 loc) · 2.22 KB
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
70
71
classdef Keylogger < handle
properties( SetAccess = private )
deviceIndex %keyboard device index
startTime %timestamp when keylogger was started
end
methods
%% CLASS CONSTRUCTOR
% called when an object is initialized
function this = Keylogger( deviceIndex )
if nargin < 1
deviceIndex = [];
end
this.deviceIndex = deviceIndex;
this.startTime = [];
end
%% PUBLIC FUNCTIONS
function startRecording( this,startTime )
KbQueueCreate( this.deviceIndex );
KbQueueStart( this.deviceIndex );
KbQueueFlush( this.deviceIndex );
if nargin > 1
this.startTime = startTime;
else
this.startTime = GetSecs();
end
end
function stopRecording( this )
KbQueueStop( this.deviceIndex );
end
function KeyLog = dumpLog( this )
this.stopRecording();
KbName( 'UnifyKeyNames' );
eventsNum = KbEventAvail( this.deviceIndex );
KeyLog = repmat( struct( 'keyName',[],'onset',[],'eventType',[],'keyCode',[],'timeStamp',[],'pressed',[] ),1,eventsNum );
for i = 1:eventsNum
KbEvent = KbEventGet( this.deviceIndex );
%'readable' output
KeyLog(i).keyName = KbName( KbEvent.Keycode );
KeyLog(i).onset = KbEvent.Time-this.startTime;
if KbEvent.Pressed
eventType = 'press';
else
eventType = 'release';
end
KeyLog(i).eventType = eventType;
%raw output
KeyLog(i).keyCode = KbEvent.Keycode;
KeyLog(i).timeStamp = KbEvent.Time;
KeyLog(i).pressed = KbEvent.Pressed;
end
end
end
methods( Static )
function cleanup()
KbQueueStop();
KbQueueRelease();
end
end
end