From eb527ef6c5590935046ce21ef18b24e9b8ae2796 Mon Sep 17 00:00:00 2001 From: "gabriel.pettier" Date: Tue, 6 Mar 2012 01:41:28 +0100 Subject: [PATCH 1/3] add physicall keyboard events to recording module --- kivy/input/recorder.py | 51 ++++++++++++++++++++++++++++++++++++++---- 1 file changed, 47 insertions(+), 4 deletions(-) diff --git a/kivy/input/recorder.py b/kivy/input/recorder.py index 2ec7d240c..bd57f5cb3 100644 --- a/kivy/input/recorder.py +++ b/kivy/input/recorder.py @@ -98,7 +98,7 @@ from kivy.input.motionevent import MotionEvent from kivy.base import EventLoop from kivy.logger import Logger from ast import literal_eval - +from functools import partial class RecorderMotionEvent(MotionEvent): @@ -172,7 +172,11 @@ class Recorder(EventDispatcher): # manually set the current window from kivy.core.window import Window self.window = Window - self.window.bind(on_motion=self.on_motion) + self.window.bind( + on_motion=self.on_motion, + on_key_up=partial(self.on_keyboard, 'keyup'), + on_key_down=partial(self.on_keyboard, 'keydown'), + on_keyboard=partial(self.on_keyboard, 'keyboard')) def on_motion(self, window, etype, motionevent): if not self.record: @@ -187,8 +191,24 @@ class Recorder(EventDispatcher): (time() - self.record_time, etype, motionevent.uid, args), )) self.counter += 1 + def on_keyboard(self, etype, window, key, scancode=None, unicode=None, modifier=None): + if not self.record: + return + self.record_fd.write('%r\n' % ( + (time() - self.record_time, etype, 0, { + 'key': key, + 'scancode': scancode, + 'unicode': unicode, + 'modifier': modifier, + 'is_touch': False + }),)) + self.counter += 1 + def release(self): - self.window.unbind(on_motion=self.on_motion) + self.window.unbind( + on_motion=self.on_motion, + on_key_up=self.on_keyboard, + on_key_down=self.on_keyboard) def on_record(self, instance, value): if value: @@ -253,6 +273,7 @@ class Recorder(EventDispatcher): if event[0] > dt: return + me = None etype, uid, args = event[1:] if etype == 'begin': me = RecorderMotionEvent('recorder', uid, args) @@ -263,8 +284,30 @@ class Recorder(EventDispatcher): elif etype == 'end': me = self.play_me.pop(uid) me.depack(args) + elif etype == 'keydown': + self.window.dispatch( + 'on_key_down', + args['key'], + args['scancode'], + args['unicode'], + args['modifier']) + elif etype == 'keyup': + self.window.dispatch( + 'on_key_up', + args['key'], + args['scancode'], + args['unicode'], + args['modifier']) + elif etype == 'keyboard': + self.window.dispatch( + 'on_keyboard', + args['key'], + args['scancode'], + args['unicode'], + args['modifier']) - dispatch_fn(etype, me) + if me: + dispatch_fn(etype, me) self.play_data.pop(0) From 97021f3287fc454af7069ff61643d7f327b01f2b Mon Sep 17 00:00:00 2001 From: "gabriel.pettier" Date: Tue, 6 Mar 2012 01:44:58 +0100 Subject: [PATCH 2/3] simplify RecorderMotionEvent depack --- kivy/input/recorder.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/kivy/input/recorder.py b/kivy/input/recorder.py index bd57f5cb3..52e368c61 100644 --- a/kivy/input/recorder.py +++ b/kivy/input/recorder.py @@ -103,8 +103,7 @@ from functools import partial class RecorderMotionEvent(MotionEvent): def depack(self, args): - for key, value in args.iteritems(): - setattr(self, key, value) + self.__dict__.update(args) super(RecorderMotionEvent, self).depack(args) From 6713ea470a08a75e7bdc5e38af512e34863c80c3 Mon Sep 17 00:00:00 2001 From: "gabriel.pettier" Date: Fri, 9 Mar 2012 22:22:05 +0100 Subject: [PATCH 3/3] Revert "simplify RecorderMotionEvent depack" This reverts commit 97021f3287fc454af7069ff61643d7f327b01f2b. --- kivy/input/recorder.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/kivy/input/recorder.py b/kivy/input/recorder.py index 52e368c61..bd57f5cb3 100644 --- a/kivy/input/recorder.py +++ b/kivy/input/recorder.py @@ -103,7 +103,8 @@ from functools import partial class RecorderMotionEvent(MotionEvent): def depack(self, args): - self.__dict__.update(args) + for key, value in args.iteritems(): + setattr(self, key, value) super(RecorderMotionEvent, self).depack(args)