mirror of
https://github.com/moparisthebest/uinput-mapper
synced 2024-11-21 16:05:00 -05:00
Initial python files.
This commit is contained in:
parent
ae1bbfaf39
commit
63f355c187
15
py/README
Normal file
15
py/README
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
Generate:
|
||||||
|
- input.h constants ; macros:
|
||||||
|
- EV_*
|
||||||
|
- KEY_*
|
||||||
|
- BTN_*
|
||||||
|
- REL_*
|
||||||
|
- ABS_*
|
||||||
|
|
||||||
|
gcc -E -dM /usr/include/linux/input.h | egrep ' (KEY|BTN|EV|REL|ABS)_[A-Za-z0-9_]+' | ( echo "#include <linux/input.h>" ; echo "input_constants_dict = {" ; sed -r 's/[^ ]+ +([^ ]+).*/"\1" : \1,/' ; echo "}" ) | gcc -E -o /dev/stdout - | grep 'input_constants_dict = {' -A 100000
|
||||||
|
|
||||||
|
|
||||||
|
Lambas for EVIO*
|
||||||
|
|
||||||
|
|
||||||
|
- uinput
|
8
py/cinput.py
Normal file
8
py/cinput.py
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
import cinput
|
||||||
|
|
||||||
|
from gen import input_constants_dict
|
||||||
|
|
||||||
|
for k, v in input_constants_dict.iteritems():
|
||||||
|
cinput.__dict__[k] = v
|
||||||
|
|
||||||
|
from linux_input import *
|
24
py/linux_input.py
Normal file
24
py/linux_input.py
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
import ctypes
|
||||||
|
|
||||||
|
# structure
|
||||||
|
|
||||||
|
"""
|
||||||
|
struct input_event {
|
||||||
|
struct timeval time;
|
||||||
|
__u16 type;
|
||||||
|
__u16 code;
|
||||||
|
__s32 value;
|
||||||
|
};
|
||||||
|
"""
|
||||||
|
|
||||||
|
class timeval(ctypes.Structure):
|
||||||
|
_fields_ = [("tv_sec", ctypes.c_long), ("tv_usec", ctypes.c_long)]
|
||||||
|
|
||||||
|
class input_event(ctypes.Structure):
|
||||||
|
_fields_ = [
|
||||||
|
("time", timeval),
|
||||||
|
("type", ctypes.c_uint16),
|
||||||
|
("code", ctypes.c_uint16),
|
||||||
|
("value", ctypes.c_int32)
|
||||||
|
]
|
||||||
|
|
25
py/map.py
Normal file
25
py/map.py
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
import cinput
|
||||||
|
import ctypes
|
||||||
|
|
||||||
|
f = open("/dev/input/event5")
|
||||||
|
|
||||||
|
|
||||||
|
while True:
|
||||||
|
#print ctypes.sizeof(input.input_event)
|
||||||
|
hoi = f.read(ctypes.sizeof(cinput.input_event))
|
||||||
|
#print repr(hoi)
|
||||||
|
|
||||||
|
e = ctypes.cast(hoi, ctypes.POINTER(cinput.input_event))
|
||||||
|
ev = e.contents
|
||||||
|
|
||||||
|
keys = filter(lambda (k, v): k.startswith("KEY_") or k.startswith("BTN_"),
|
||||||
|
cinput.input_constants_dict.iteritems())
|
||||||
|
|
||||||
|
if ev.type == cinput.EV_KEY:
|
||||||
|
for k, v in keys:
|
||||||
|
if v == ev.code:
|
||||||
|
print k
|
||||||
|
#print e.contents.type
|
||||||
|
#print e.contents.code
|
||||||
|
#print e.contents.value
|
||||||
|
|
Loading…
Reference in New Issue
Block a user