Experimental networked input.

This commit is contained in:
Merlijn Wajer 2013-05-09 16:10:28 +02:00
parent e1b85874ba
commit 19868360a3
3 changed files with 75 additions and 14 deletions

View File

@ -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)

View File

@ -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

50
py/read.py Normal file
View File

@ -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