uinput-mapper/py/create.py

51 lines
1.0 KiB
Python
Raw Normal View History

import linux_uinput, ctypes, fcntl, os, sys
2013-04-19 19:10:16 -04:00
from cinput import *
2013-04-21 06:42:51 -04:00
from mapper import KeyMapper, parse_conf
from example_conf import config
2013-05-09 10:10:28 -04:00
from linux_input import timeval, input_event
import imp
2013-05-09 10:10:28 -04:00
try:
import cPickle as pickle
except ImportError:
import pickle
import optparse
parser = optparse.OptionParser(description='Create input devices. '
'TODO')
parser.add_option('-C', '--compat', action='store_true',
help='Enable compatibility mode; for Python < 2.7')
2013-05-10 11:33:25 -04:00
args, cfg = parser.parse_args()
# Unpickle from stdin ; currently this is the default and only way
2013-05-09 10:10:28 -04:00
f = pickle.Unpickler(sys.stdin)
2013-05-09 10:10:28 -04:00
conf = f.load()
2013-05-10 11:33:25 -04:00
for path in cfg:
config_merge = imp.load_source('', path).config_merge
config_merge(conf)
2013-05-09 10:10:28 -04:00
m = KeyMapper(conf)
2013-05-09 10:10:28 -04:00
d = UInputDevice()
m.expose(d)
d.setup('Example input device')
while True:
if not args.compat:
ev = f.load()
else:
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])
2013-04-18 19:11:56 -04:00
2013-04-21 06:42:51 -04:00
ev = m.map_event(ev)
2013-04-18 19:11:56 -04:00
d.fire_event(ev)