mirror of
https://github.com/moparisthebest/uinput-mapper
synced 2024-11-24 16:52:14 -05:00
Initial work on create/uinput tests.
This commit is contained in:
parent
1bddfc11ad
commit
b6c5b6bee1
79
py/create.py
Normal file
79
py/create.py
Normal file
@ -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
|
||||
# }
|
||||
# }
|
||||
# },
|
||||
# }
|
||||
#}
|
@ -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)
|
||||
|
@ -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)
|
||||
]
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user