Initial python files.

This commit is contained in:
Merlijn Wajer 2013-04-18 00:34:45 +02:00
parent ae1bbfaf39
commit 63f355c187
4 changed files with 72 additions and 0 deletions

15
py/README Normal file
View 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
View 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
View 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
View 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