Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Don't count repeated keys in nrkeys #8

Merged
merged 1 commit into from

2 participants

@leafo

Here's the code for issue #7

@gurgeh
Owner

Thanks for the patch! I'll review it shortly

@gurgeh gurgeh merged commit 4b2eff7 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 22 additions and 13 deletions.
  1. +19 −10 activity_store.py
  2. +2 −2 models.py
  3. +1 −1  sniff_x.py
View
29 activity_store.py
@@ -13,6 +13,12 @@
#Mouse buttons: left button: 1, middle: 2, right: 3, scroll up: 4, down:5
+class KeyPress:
+ def __init__(self, key, time, is_repeat):
+ self.key = key
+ self.time = time
+ self.is_repeat = is_repeat
+
class ActivityStore:
def __init__(self, db_name, encrypter=None, store_text=True):
self.session_maker = models.initialize(db_name)
@@ -29,8 +35,7 @@ def __init__(self, db_name, encrypter=None, store_text=True):
self.specials_in_row = 0
self.curtext = u""
- self.keys = []
- self.timings = []
+ self.key_presses = []
self.last_key_time = time.time()
self.started = NOW()
@@ -88,20 +93,25 @@ def store_click(self, button, press):
self.nrmoves = 0
def store_keys(self):
- if self.timings:
+ if self.key_presses:
self.maybe_end_specials()
+ keys = [press.key for press in self.key_presses]
+ timings = [press.time for press in self.key_presses]
+
+ nrkeys = reduce(lambda count, press: count + (not press.is_repeat and 1 or 0), self.key_presses, 0)
+
if not self.store_text:
- self.keys = []
+ keys = []
self.curtext = u""
- self.session.add(Keys(self.curtext.encode('utf8'), self.keys, self.timings, self.started, self.cur_win_proc, self.cur_win_id, self.cur_geo_id))
+ self.session.add(Keys(self.curtext.encode('utf8'), keys, timings, nrkeys, self.started, self.cur_win_proc, self.cur_win_id, self.cur_geo_id))
+
self.trycommit()
self.started = NOW()
self.curtext = u""
- self.timings = []
- self.keys = []
+ self.key_presses = []
self.last_key_time = time.time()
def get_cur_window(self):
@@ -173,7 +183,7 @@ def log_cur_window(self):
self.check_geometry()
- def got_key(self, keycode, state, s, press):
+ def got_key(self, keycode, state, s, press, repeat):
now = time.time()
self.log_cur_window()
if press:
@@ -190,8 +200,7 @@ def got_key(self, keycode, state, s, press):
self.specials_in_row += 1
self.lastspecial = s
if self.specials_in_row < 2:
- self.keys.append(s)
- self.timings.append(now - self.last_key_time)
+ self.key_presses.append(KeyPress(s, now - self.last_key_time, repeat))
self.last_key_time = now
def got_mouse_click(self, button, press):
View
4 models.py
@@ -131,14 +131,14 @@ class Keys(SpookMixin, Base):
keys = Column(Binary)
timings = Column(Binary)
- def __init__(self, text, keys, timings, started, process_id, window_id, geometry_id):
+ def __init__(self, text, keys, timings, nrkeys, started, process_id, window_id, geometry_id):
ztimings = zlib.compress(json.dumps(timings))
zkeys = maybe_encrypt(zlib.compress(json.dumps(keys)))
ztext = maybe_encrypt(text)
self.text = ztext
self.keys = zkeys
- self.nrkeys = len(keys)
+ self.nrkeys = nrkeys
self.timings = ztimings
self.started = started
View
2  sniff_x.py
@@ -101,7 +101,7 @@ def get_key_name(self, keycode, state):
return self.lookup_keysym(cn)
def key_event(self, event):
- return event.detail, event.state, self.get_key_name(event.detail, event.state), event.type == X.KeyPress
+ return event.detail, event.state, self.get_key_name(event.detail, event.state), event.type == X.KeyPress, event.sequence_number == 1
def button_event(self, event):
return event.detail, event.type == X.ButtonPress
Something went wrong with that request. Please try again.