2013-05-14 17:46:18 -04:00
|
|
|
#!/usr/bin/env python
|
2013-05-09 10:10:28 -04:00
|
|
|
import linux_uinput, ctypes, fcntl, os, sys
|
|
|
|
from cinput import *
|
|
|
|
from mapper import KeyMapper, parse_conf
|
|
|
|
|
|
|
|
try:
|
|
|
|
import cPickle as pickle
|
|
|
|
except ImportError:
|
|
|
|
import pickle
|
|
|
|
|
2013-05-10 05:05:31 -04:00
|
|
|
import optparse
|
2013-05-09 10:10:28 -04:00
|
|
|
|
2013-05-14 17:46:18 -04:00
|
|
|
_usage = 'input-read /dev/input/event<0> ... /dev/input/event<N>'
|
2013-05-14 15:30:03 -04:00
|
|
|
parser = optparse.OptionParser(description='Read input devices.',
|
|
|
|
usage = _usage,
|
|
|
|
version='0.01')
|
2013-05-10 05:05:31 -04:00
|
|
|
parser.add_option('-D', '--dump', action='store_false',
|
|
|
|
default=True, help='Dump will marshall all the events to stdout')
|
2013-05-09 10:10:28 -04:00
|
|
|
|
2013-05-10 05:05:31 -04:00
|
|
|
parser.add_option('-C', '--compat', action='store_true',
|
|
|
|
help='Enable compatibility mode; for Python < 2.7')
|
2013-05-09 10:10:28 -04:00
|
|
|
|
2013-05-10 11:33:25 -04:00
|
|
|
args, input_file = parser.parse_args()
|
2013-05-10 05:05:31 -04:00
|
|
|
|
|
|
|
|
2013-05-10 11:33:25 -04:00
|
|
|
if len(input_file) == 0:
|
2013-05-10 05:05:31 -04:00
|
|
|
parser.print_help()
|
|
|
|
exit(0)
|
2013-05-09 10:10:28 -04:00
|
|
|
|
2013-05-10 05:05:31 -04:00
|
|
|
# TODO: Support multiple input files + epoll; InputDevices?
|
2013-05-10 11:33:25 -04:00
|
|
|
f = InputDevice(input_file[0])
|
2013-05-10 05:05:31 -04:00
|
|
|
|
|
|
|
config = parse_conf(f)
|
|
|
|
m = KeyMapper(config)
|
|
|
|
|
|
|
|
if args.dump:
|
|
|
|
print 'Version:', f.get_version()
|
|
|
|
print f.get_name()
|
|
|
|
|
|
|
|
d = f.get_exposed_events()
|
|
|
|
for k, v in d.iteritems():
|
|
|
|
print k + ':', ', '.join(v)
|
|
|
|
|
|
|
|
else:
|
|
|
|
p = pickle.Pickler(sys.stdout)
|
|
|
|
|
|
|
|
p.dump(config)
|
2013-05-09 10:10:28 -04:00
|
|
|
|
|
|
|
sys.stdout.flush()
|
|
|
|
|
2013-05-10 05:05:31 -04:00
|
|
|
while True:
|
|
|
|
# TODO: Poll multiple files ; add file description (not descriptor...)
|
|
|
|
# f, ev = fs.next_event()
|
|
|
|
ev = f.next_event()
|
2013-05-09 10:10:28 -04:00
|
|
|
|
2013-05-10 05:05:31 -04:00
|
|
|
if args.dump:
|
|
|
|
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
|
2013-05-09 10:10:28 -04:00
|
|
|
|
2013-05-10 05:05:31 -04:00
|
|
|
else:
|
|
|
|
if not args.compat:
|
|
|
|
p.dump(ev)
|
|
|
|
else:
|
|
|
|
# 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))
|
2013-05-09 10:10:28 -04:00
|
|
|
|
2013-05-10 05:05:31 -04:00
|
|
|
sys.stdout.flush()
|