diff --git a/py/create.py b/py/create.py new file mode 100644 index 0000000..1192fe5 --- /dev/null +++ b/py/create.py @@ -0,0 +1,79 @@ +import cinput, linux_uinput, ctypes, fcntl + +def open_uinput(): + try: + f = open('/dev/uinput', 'w+') + except IOError: + try: + f = open('/dev/input/uinput', 'w+') + except IOError: + print 'FAIL MUCH?' + return None + return f + +def handle_specs(f, s): + print 'ioctl:', fcntl.ioctl(f, linux_uinput.UI_SET_EVBIT, cinput.EV_KEY) + print 'ioctl:', fcntl.ioctl(f, linux_uinput.UI_SET_KEYBIT, cinput.KEY_UP) + + +def create_device(specs): + f = open_uinput() + + if not f: + print 'Failed to open uinput' + return None + + # Add keys, etc + handle_specs(f, specs) + + # Allocate other info + # TODO: + # * Make sure the uidev structure is correct + # * Make sure that we are setting the values in the structure + # * Make sure the value is properly written to 'f' + uidev = linux_uinput.uinput_user_dev() + + uidev.name = 'key2joy\0' + uidev._id.bustype = 0x03 # BUS_USB (TODO) + uidev._id.vendor = 0x42 + uidev._id.product = 0xBEBE + uidev._id.product = 1 + + buf = buffer(uidev)[:] + print repr(buf) + + # Write dev info + f.write(buf) + + print 'ioctl:', fcntl.ioctl(f, linux_uinput.UI_DEV_CREATE) + + return f + +create_device(None) + +print 'Hoi' +import time +time.sleep(5) +# config +#dev = { +# "input_devices" : [ +# ("/dev/input/event3", "keyboard1"), +# ], +# "type" : "mouse", # "mixed" "mouse" "keyboard" "joystick" "clone"? +# "keymap" : { +# "any" : { # From +# EV_KEY : { +# KEY_UP : { +# "type" : EV_REL +# "key" : REL_X +# "value" : lambda x: -x*10 +# } +# KEY_DOWN : { +# "type": EV_REL +# "key": REL_X +# "value" : lambda x: x*10 +# } +# } +# }, +# } +#} diff --git a/py/ioctlhelp.py b/py/ioctlhelp.py index 6bf7bbf..5448ac6 100644 --- a/py/ioctlhelp.py +++ b/py/ioctlhelp.py @@ -27,8 +27,8 @@ _IOC_READ = 2 def IOC(_dir, _type, nr, size): if type(size) in (str, unicode): size = struct.calcsize(size) - return _dir << _IOC_DIRSHIFT | _type << _IOC_TYPESHIFT | \ - nr << _IOC_NRSHIFT | size << _IOC_SIZESHIFT + return _dir << _IOC_DIRSHIFT | _type << _IOC_TYPESHIFT | \ + nr << _IOC_NRSHIFT | size << _IOC_SIZESHIFT IO = lambda _type, nr: IOC(_IOC_NONE, _type, nr, 0) diff --git a/py/linux_uinput.py b/py/linux_uinput.py index 170f3a8..6fe7a61 100644 --- a/py/linux_uinput.py +++ b/py/linux_uinput.py @@ -35,17 +35,17 @@ EV_UINPUT = 0x0101 UI_FF_UPLOAD = 1 UI_FF_ERASE = 2 - import ctypes UINPUT_MAX_NAME_SIZE = 80 class uinput_user_dev(ctypes.Structure): _fields_ = [ ("name", ctypes.c_char * UINPUT_MAX_NAME_SIZE), - ("id", linux_input.input_id), + ("_id", linux_input.input_id), ("ff_effects_max", ctypes.c_uint32), ("absmax", ctypes.c_int32), ("absmin", ctypes.c_int32), ("absfuzz", ctypes.c_int32), ("absflac", ctypes.c_int32) ] +