mirror of
https://github.com/moparisthebest/uinput-mapper
synced 2024-12-23 04:08:48 -05:00
4323e92a13
read.py now deprecates test.py I went with optparse rather than argparse to support Python <2.7. Switching to argparse later should not be that hard. Configurations still need to be extended with, among other things: * Name for the device
49 lines
1.2 KiB
Python
49 lines
1.2 KiB
Python
import cinput
|
|
|
|
# XXX: Also parse name, etc
|
|
def parse_conf(f):
|
|
conf = {}
|
|
e = f.get_exposed_events()
|
|
for k, v in e.iteritems():
|
|
t = cinput.events[k]
|
|
if t == cinput.EV_SYN:
|
|
continue
|
|
|
|
conf[t] = {}
|
|
|
|
for key in v:
|
|
tt = cinput.event_keys[t][key]
|
|
conf[t][tt] = {
|
|
'type' : t,
|
|
'code' : tt,
|
|
'value' : None
|
|
#'value' : lambda x: x
|
|
}
|
|
|
|
return conf
|
|
|
|
class KeyMapper(object):
|
|
def __init__(self, config):
|
|
self._config = config
|
|
|
|
def map_event(self, ev):
|
|
_type = ev.type
|
|
if _type in self._config:
|
|
typemaps = self._config[_type]
|
|
if ev.code in typemaps:
|
|
info = typemaps[ev.code]
|
|
ev.type = info['type']
|
|
ev.code = info['code']
|
|
if info['value'] is not None:
|
|
ev.value = info['value'](ev.value)
|
|
else:
|
|
ev.value = ev.value
|
|
|
|
return ev
|
|
|
|
def expose(self, d):
|
|
for evt, v in self._config.iteritems():
|
|
for code, dat in v.iteritems():
|
|
d.expose_event_type(dat['type'])
|
|
d.expose_event(dat['type'], dat['code'])
|