mirror of
https://github.com/moparisthebest/uinput-mapper
synced 2025-02-07 02:20:17 -05:00
More dynamic, still WIP.
This commit is contained in:
parent
be7359e227
commit
9c5c57a7eb
58
py/cinput.py
58
py/cinput.py
@ -1,31 +1,69 @@
|
|||||||
import cinput
|
#TODO: remove this soon
|
||||||
|
|
||||||
from gen import input_constants_dict
|
from gen import input_constants_dict as icd
|
||||||
|
|
||||||
for k, v in input_constants_dict.iteritems():
|
# TODO: Just combine linux_input and cinput and use locals() to set the
|
||||||
cinput.__dict__[k] = v
|
# variables rather than the silly hack
|
||||||
|
for k, v in icd.iteritems():
|
||||||
|
locals()[k] = v
|
||||||
|
|
||||||
from linux_input import *
|
from linux_input import *
|
||||||
|
|
||||||
event_types = [EV_SYN, EV_KEY, EV_REL, EV_ABS, EV_MSC, EV_SW,
|
|
||||||
EV_LED, EV_SND, EV_REP, EV_FF, EV_PWR, EV_FF_STATUS]
|
|
||||||
|
|
||||||
rdict = lambda x: dict(map(lambda (k, v): (v, k), x))
|
rdict = lambda x: dict(map(lambda (k, v): (v, k), x))
|
||||||
|
|
||||||
|
events = filter(lambda (k, v): k in ["EV_SYN", "EV_KEY", "EV_REL",
|
||||||
|
"EV_ABS", "EV_MSC", "EV_SW", "EV_LED", "EV_SND", "EV_REP",
|
||||||
|
"EV_FF", "EV_PWR", "EV_FF_STATUS"], icd.iteritems())
|
||||||
|
rev_events = rdict(events)
|
||||||
|
|
||||||
|
|
||||||
|
# TODO: Get proper ``names'' like evtest:
|
||||||
|
"""
|
||||||
|
static const char * const * const names[EV_MAX + 1] = {
|
||||||
|
[0 ... EV_MAX] = NULL,
|
||||||
|
[EV_SYN] = events, [EV_KEY] = keys,
|
||||||
|
[EV_REL] = relatives, [EV_ABS] = absolutes,
|
||||||
|
[EV_MSC] = misc, [EV_LED] = leds,
|
||||||
|
[EV_SND] = sounds, [EV_REP] = repeats,
|
||||||
|
[EV_SW] = switches,
|
||||||
|
[EV_FF] = force, [EV_FF_STATUS] = forcestatus,
|
||||||
|
};
|
||||||
|
"""
|
||||||
|
|
||||||
keys = filter(lambda (k, v): k.startswith("KEY_") or k.startswith("BTN_"),
|
keys = filter(lambda (k, v): k.startswith("KEY_") or k.startswith("BTN_"),
|
||||||
input_constants_dict.iteritems())
|
icd.iteritems())
|
||||||
rev_keys = rdict(keys)
|
rev_keys = rdict(keys)
|
||||||
|
|
||||||
absaxes = filter(lambda (k, v): k.startswith("ABS_"),
|
absaxes = filter(lambda (k, v): k.startswith("ABS_"),
|
||||||
input_constants_dict.iteritems())
|
icd.iteritems())
|
||||||
rev_absaxes = rdict(absaxes)
|
rev_absaxes = rdict(absaxes)
|
||||||
|
|
||||||
rel = filter(lambda (k, v): k.startswith("REL_"),
|
rel = filter(lambda (k, v): k.startswith("REL_"),
|
||||||
input_constants_dict.iteritems())
|
icd.iteritems())
|
||||||
rev_rel = rdict(rel)
|
rev_rel = rdict(rel)
|
||||||
|
|
||||||
syn = filter(lambda (k, v): k.startswith("SYN_"),
|
syn = filter(lambda (k, v): k.startswith("SYN_"),
|
||||||
input_constants_dict.iteritems())
|
icd.iteritems())
|
||||||
rev_syn = rdict(syn)
|
rev_syn = rdict(syn)
|
||||||
|
|
||||||
del rdict
|
del rdict
|
||||||
|
|
||||||
|
misc = {}
|
||||||
|
|
||||||
|
leds = sounds = repeats = switches = force = forcestatus = None
|
||||||
|
|
||||||
|
event_keys = {
|
||||||
|
EV_SYN: rev_syn,
|
||||||
|
EV_KEY: rev_keys,
|
||||||
|
EV_REL: rev_rel,
|
||||||
|
EV_ABS: rev_absaxes,
|
||||||
|
EV_MSC: misc,
|
||||||
|
EV_LED: leds,
|
||||||
|
EV_SND: sounds,
|
||||||
|
EV_REP: repeats,
|
||||||
|
EV_SW: switches,
|
||||||
|
EV_FF: force,
|
||||||
|
EV_FF_STATUS: forcestatus
|
||||||
|
|
||||||
|
}
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
import ctypes
|
import ctypes
|
||||||
|
|
||||||
# structure
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
struct input_event {
|
struct input_event {
|
||||||
struct timeval time;
|
struct timeval time;
|
||||||
|
20
py/map.py
20
py/map.py
@ -3,7 +3,7 @@ import ctypes
|
|||||||
|
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
f = open(sys.argv[1] if len(sys.argv) else "/dev/input/event8")
|
f = open(sys.argv[1] if len(sys.argv) == 2 else "/dev/input/event8")
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
estr = f.read(ctypes.sizeof(cinput.input_event))
|
estr = f.read(ctypes.sizeof(cinput.input_event))
|
||||||
@ -11,16 +11,8 @@ while True:
|
|||||||
e = ctypes.cast(estr, ctypes.POINTER(cinput.input_event))
|
e = ctypes.cast(estr, ctypes.POINTER(cinput.input_event))
|
||||||
ev = e.contents
|
ev = e.contents
|
||||||
|
|
||||||
if ev.type == cinput.EV_KEY:
|
print 'Event type:', cinput.rev_events[ev.type]
|
||||||
print cinput.rev_keys[ev.code]
|
try:
|
||||||
if ev.type == cinput.EV_REL:
|
print 'Code:', cinput.event_keys[ev.type][ev.code]
|
||||||
print cinput.rev_rel[ev.code]
|
except KeyError:
|
||||||
if ev.type == cinput.EV_ABS:
|
pass
|
||||||
print cinput.rev_absaxes[ev.code]
|
|
||||||
if ev.type == cinput.EV_SYN:
|
|
||||||
print cinput.rev_syn[ev.code]
|
|
||||||
|
|
||||||
#print e.contents.type
|
|
||||||
#print e.contents.code
|
|
||||||
#print e.contents.value
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user