mirror of
https://github.com/moparisthebest/uinput-mapper
synced 2025-02-07 02:20:17 -05:00
Extend uinput; replace open with os.open.
This commit is contained in:
parent
9113cb02b7
commit
c8e7b07805
19
py/cinput.py
19
py/cinput.py
@ -48,6 +48,10 @@ def get_keys(f, ev):
|
|||||||
|
|
||||||
|
|
||||||
def copy_event(estr):
|
def copy_event(estr):
|
||||||
|
"""
|
||||||
|
Copy event from a string returned by read().
|
||||||
|
We return a copy because the string will probably be freed.
|
||||||
|
"""
|
||||||
e = ctypes.cast(estr, ctypes.POINTER(input_event))
|
e = ctypes.cast(estr, ctypes.POINTER(input_event))
|
||||||
ev = e.contents
|
ev = e.contents
|
||||||
|
|
||||||
@ -56,7 +60,7 @@ def copy_event(estr):
|
|||||||
class InputDevice(object):
|
class InputDevice(object):
|
||||||
|
|
||||||
def __init__(self, path):
|
def __init__(self, path):
|
||||||
self._f = open(path)
|
self._f = os.open(path, os.O_RDONLY)
|
||||||
|
|
||||||
def get_version(self):
|
def get_version(self):
|
||||||
return get_input_version(self._f)
|
return get_input_version(self._f)
|
||||||
@ -79,7 +83,7 @@ class InputDevice(object):
|
|||||||
return d
|
return d
|
||||||
|
|
||||||
def next_event(self):
|
def next_event(self):
|
||||||
estr = self._f.read(ctypes.sizeof(input_event))
|
estr = os.read(self._f, ctypes.sizeof(input_event))
|
||||||
return copy_event(estr)
|
return copy_event(estr)
|
||||||
|
|
||||||
def get_fd(self):
|
def get_fd(self):
|
||||||
@ -87,7 +91,7 @@ class InputDevice(object):
|
|||||||
|
|
||||||
|
|
||||||
def __del__(self):
|
def __del__(self):
|
||||||
self._f.close()
|
os.close(self._f)
|
||||||
|
|
||||||
|
|
||||||
def open_uinput():
|
def open_uinput():
|
||||||
@ -145,6 +149,15 @@ class UInputDevice(object):
|
|||||||
# direct methods / programming it rather than just the dict as config
|
# direct methods / programming it rather than just the dict as config
|
||||||
self._f = write_uinput_device_info(name)
|
self._f = write_uinput_device_info(name)
|
||||||
|
|
||||||
|
def expose_event(evt, evk):
|
||||||
|
evbit = evbits[ev]
|
||||||
|
fcntl.ioctl(self._f, evbit, evk)
|
||||||
|
|
||||||
|
def fire_event(ev):
|
||||||
|
"""
|
||||||
|
"""
|
||||||
|
os.write(self._f, buffer(ev)[:])
|
||||||
|
|
||||||
def __del__(self):
|
def __del__(self):
|
||||||
free_uinput_device(self._f)
|
free_uinput_device(self._f)
|
||||||
|
|
||||||
|
@ -1,14 +1,14 @@
|
|||||||
import cinput, linux_uinput, ctypes, fcntl, os
|
import linux_uinput, ctypes, fcntl, os
|
||||||
|
|
||||||
|
|
||||||
from cinput import *
|
from cinput import *
|
||||||
|
|
||||||
def handle_specs(f, s):
|
def handle_specs(f, s):
|
||||||
print 'ioctl:', fcntl.ioctl(f, UI_SET_EVBIT, cinput.EV_KEY)
|
print 'ioctl:', fcntl.ioctl(f, UI_SET_EVBIT, EV_KEY)
|
||||||
print 'ioctl:', fcntl.ioctl(f, UI_SET_KEYBIT, cinput.KEY_UP)
|
print 'ioctl:', fcntl.ioctl(f, UI_SET_KEYBIT, KEY_UP)
|
||||||
|
|
||||||
|
|
||||||
d = cinput.UInputDevice('Example input device', None)
|
d = UInputDevice('Example input device', None)
|
||||||
|
|
||||||
import time
|
import time
|
||||||
time.sleep(5)
|
time.sleep(5)
|
||||||
|
@ -24,6 +24,18 @@ UI_SET_PHYS = IOW(UINPUT_IOCTL_BASE, 108, '@i')
|
|||||||
UI_SET_SWBIT = IOW(UINPUT_IOCTL_BASE, 109, '@i')
|
UI_SET_SWBIT = IOW(UINPUT_IOCTL_BASE, 109, '@i')
|
||||||
UI_SET_PROPBIT = IOW(UINPUT_IOCTL_BASE, 110, '@i')
|
UI_SET_PROPBIT = IOW(UINPUT_IOCTL_BASE, 110, '@i')
|
||||||
|
|
||||||
|
# TODO: Lacking PHYS and PROP
|
||||||
|
evbits = {
|
||||||
|
linux_input.EV_KEY : UI_SET_KEYBIT,
|
||||||
|
linux_input.EV_REL : UI_SET_RELBIT,
|
||||||
|
linux_input.EV_ABS : UI_SET_ABSBIT,
|
||||||
|
linux_input.EV_MSC : UI_SET_MSCBIT,
|
||||||
|
linux_input.EV_LED : UI_SET_LEDBIT,
|
||||||
|
linux_input.EV_SND : UI_SET_SNDBIT,
|
||||||
|
linux_input.EV_FF : UI_SET_FFBIT,
|
||||||
|
linux_input.EV_SW : UI_SET_SWBIT
|
||||||
|
}
|
||||||
|
|
||||||
# TODO
|
# TODO
|
||||||
#define UI_BEGIN_FF_UPLOAD _IOWR(UINPUT_IOCTL_BASE, 200, struct uinput_ff_upload)
|
#define UI_BEGIN_FF_UPLOAD _IOWR(UINPUT_IOCTL_BASE, 200, struct uinput_ff_upload)
|
||||||
#define UI_END_FF_UPLOAD _IOW(UINPUT_IOCTL_BASE, 201, struct uinput_ff_upload)
|
#define UI_END_FF_UPLOAD _IOW(UINPUT_IOCTL_BASE, 201, struct uinput_ff_upload)
|
||||||
|
@ -15,10 +15,6 @@ for k, v in d.iteritems():
|
|||||||
|
|
||||||
while True:
|
while True:
|
||||||
ev = f.next_event()
|
ev = f.next_event()
|
||||||
#estr = f._f.read(ctypes.sizeof(input_event))
|
|
||||||
|
|
||||||
#e = ctypes.cast(estr, ctypes.POINTER(input_event))
|
|
||||||
#ev = e.contents
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
print ev.time.tv_sec, ev.time.tv_usec
|
print ev.time.tv_sec, ev.time.tv_usec
|
||||||
|
Loading…
Reference in New Issue
Block a user