diff --git a/py/create.py b/py/create.py index 12300cf..21b9821 100644 --- a/py/create.py +++ b/py/create.py @@ -2,25 +2,32 @@ import linux_uinput, ctypes, fcntl, os, sys from cinput import * from mapper import KeyMapper, parse_conf from example_conf import config +from linux_input import timeval, input_event -clone = False -f = InputDevice(sys.argv[1] if len(sys.argv) == 2 else "/dev/input/event3") +try: + import cPickle as pickle +except ImportError: + import pickle + +f = pickle.Unpickler(sys.stdin) + +conf = f.load() +m = KeyMapper(conf) + d = UInputDevice() - -if clone: - conf = parse_conf(f) - m = KeyMapper(conf) -else: - m = KeyMapper(config) - m.expose(d) - -d.setup('Example input device' ) +d.setup('Example input device') while True: - ev = f.next_event() + ev = f.load() + # Use code below rather than the line above if you use an old python + # version (also edit read.py) + + #ev_p = f.load() + #ti = timeval(ev_p[0], ev_p[1]) + #ev = input_event(ti, ev_p[2], ev_p[3], ev_p[4]) ev = m.map_event(ev) diff --git a/py/mapper.py b/py/mapper.py index da772fe..0359211 100644 --- a/py/mapper.py +++ b/py/mapper.py @@ -15,7 +15,8 @@ def parse_conf(f): conf[t][tt] = { 'type' : t, 'code' : tt, - 'value' : lambda x: x + 'value' : None + #'value' : lambda x: x } return conf @@ -32,7 +33,10 @@ class KeyMapper(object): info = typemaps[ev.code] ev.type = info['type'] ev.code = info['code'] - ev.value = info['value'](ev.value) + if info['value'] is not None: + ev.value = info['value'](ev.value) + else: + ev.value = ev.value return ev diff --git a/py/read.py b/py/read.py new file mode 100644 index 0000000..082fbb7 --- /dev/null +++ b/py/read.py @@ -0,0 +1,50 @@ +import linux_uinput, ctypes, fcntl, os, sys +from cinput import * +from mapper import KeyMapper, parse_conf +from example_conf import config + +clone = True + +f = InputDevice(sys.argv[1] if len(sys.argv) == 2 else "/dev/input/event3") + +if clone: + config = parse_conf(f) + m = KeyMapper(config) +else: + m = KeyMapper(config) + +try: + import cPickle as pickle +except ImportError: + import pickle +p = pickle.Pickler(sys.stdout) + +p.dump(config) +sys.stdout.flush() + +#d = UInputDevice() +#m.expose(d) +#d.setup('Example input device') + + +while True: + ev = f.next_event() + p.dump(ev) + + # Use this rather than the line above if you use an old python version (also + # edit create.py) + #p.dump((ev.time.tv_sec, ev.time.tv_usec, ev.type, ev.code, ev.value)) + + sys.stdout.flush() + + #ev = m.map_event(ev) + + #d.fire_event(ev) + + #try: + # print ev.time.tv_sec, ev.time.tv_usec + # s = '%s %s %d' % (rev_events[ev.type], rev_event_keys[ev.type][ev.code], ev.value) + # print 'Event type:', s + + #except KeyError: + # pass