#!/usr/bin/env python import linux_uinput, ctypes, fcntl, os, sys from cinput import * from mapper import KeyMapper, parse_conf, pretty_conf_print, \ get_exported_device_count from linux_input import timeval, input_event try: import cPickle as pickle except ImportError: import pickle import imp import optparse _usage = 'python create.py /path/to/config1 ... /path/to/configN' parser = optparse.OptionParser(description='Create input devices.', usage=_usage, version='0.01' ) parser.add_option('-C', '--compat', action='store_true', help='Enable compatibility mode; for Python < 2.7') args, cfg = parser.parse_args() # Unpickle from stdin ; currently this is the default and only way in_f = pickle.Unpickler(sys.stdin) nifd = in_f.load() print 'Got', nifd, 'inputs' conf = in_f.load() for path in cfg: config_merge = imp.load_source('', path).config_merge config_merge(conf) pretty_conf_print(conf) m = KeyMapper(conf) # TODO: Get amount of uinput devices to export nofd = get_exported_device_count(conf) ofs = [] for f in xrange(nofd): d = UInputDevice() m.expose(d, f) d.setup('Example input device') ofs.append(d) while True: if not args.compat: fd, ev = in_f.load() else: fd, ev_p = in_f.load() ti = timeval(ev_p[0], ev_p[1]) ev = input_event(ti, ev_p[2], ev_p[3], ev_p[4]) idx, ev = m.map_event(ev, fd) d = ofs[idx] d.fire_event(ev)