final commit on sixth

xkb
sezanzeb 4 years ago committed by sezanzeb
parent fc52d4fad8
commit d02e3eaa13

@ -83,11 +83,20 @@ keycode, use a custom mapping that starts at 255 and just offsets xmodmap
by 255. The correct capabilities need to exist this time. Everything below
255 is disabled. This mapping is applied to key-mappers custom /dev node.
Each preset uses the same key-mapper-offset-symbol file and the same
empty-symbol file to disable the keys of the original device. This avoids
having to manage user defined presets in /usr. But it could be extended to
support custom xkb symbol files in the future, to e.g. map `10` to 'b', and
`shift+10` to 'c'.
However, if you try to map Shift to button 10 of your mouse, and use
mouse-shift + keyboard-1, you need to press keyboard-1 again to do anything.
I assume this is because:
- mouse-10 down
- keymapper says: shift down
- keyboard-10 down (down again? X/Linux ignores that)
- keyboard-10 up
- keyboard-10 down, "!" written
**Seventh, final solution** By grabbing the mouse device (EVIOCGRAB) this
won't happen. Since this prevents all the keycodes from doing stuff, no
empty xkb symbols file is needed anymore. I can basically do the fifth idea
from above.
# How I would have liked it to be

@ -62,7 +62,12 @@ class _GetDevicesProcess(multiprocessing.Process):
for device in devices:
# only keyboard devices
# https://www.kernel.org/doc/html/latest/input/event-codes.html
if evdev.ecodes.EV_KEY not in device.capabilities().keys():
capabilities = device.capabilities().keys()
if evdev.ecodes.EV_KEY not in capabilities:
continue
if evdev.ecodes.EV_REL in capabilities:
# skip devices that control movement
continue
usb = device.phys.split('/')[0]

@ -109,6 +109,13 @@ class KeycodeInjector:
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
device = evdev.InputDevice(path)
"""try:
# grab to avoid e.g. the disabled keycode of 10 to confuse X,
# especially when one of the buttons of your mouse also uses 10
device.grab()
except IOError:
logger.error('Cannot grab %s', path)"""
# foo = evdev.InputDevice('/dev/input/event2')
keymapper_device = evdev.UInput(
name=DEV_NAME,
@ -127,7 +134,7 @@ class KeycodeInjector:
if event.type != evdev.ecodes.EV_KEY:
continue
if event.code == 2:
if event.value == 2:
# linux does them itself, no need to trigger them
continue
@ -141,7 +148,7 @@ class KeycodeInjector:
# unknown keycode, forward it
continue
else:
target_keycode = internal_mapping.get_keycode(character)
target_keycode = system_mapping.get_keycode(character)
if target_keycode is None:
logger.error(
'Cannot find character %s in the internal mapping',
@ -158,8 +165,8 @@ class KeycodeInjector:
# fine. I came up with that after randomly poking around in,
# frustration. I don't know of any helpful resource that
# explains this
# TODO still needed? if no, add to HELP.md
time.sleep(0.015)
# TODO still needed? if yes, add to HELP.md
time.sleep(0.005)
logger.debug2(
'got code:%s value:%s, maps to code:%s char:%s',

Loading…
Cancel
Save