can map shoulder buttons

xkb
sezanzeb 4 years ago committed by sezanzeb
parent cbf97fd44c
commit 91b9ad5754

@ -47,7 +47,8 @@ If you can't find what you need, consult
##### Gamepads
Tested with the XBOX 360 Gamepad. Joystick movements will be translated
to mouse movements and buttons can be mapped to keycodes or macros.
to mouse movements and buttons can be mapped to keycodes or macros. This is
only partially done though.
## Installation

@ -45,9 +45,6 @@ INITIAL_CONFIG = {
'non_linearity': 4,
'pointer_speed': 80,
},
'triggers': {
'button_threshold': 0.5
},
}
}

@ -36,10 +36,8 @@ from keymapper.config import config
JOYSTICK = [
evdev.ecodes.ABS_X,
evdev.ecodes.ABS_Y,
evdev.ecodes.ABS_Z,
evdev.ecodes.ABS_RX,
evdev.ecodes.ABS_RY,
evdev.ecodes.ABS_RZ,
]

@ -212,17 +212,19 @@ class KeycodeInjector:
if abs_to_rel:
del capabilities[ecodes.EV_ABS]
# those are the requirements to recognize it as mouse
# on my system. REL_X and REL_Y are of course required to
# accept the events that the mouse-movement-mapper writes.
capabilities[ecodes.EV_REL] = [
evdev.ecodes.REL_X,
evdev.ecodes.REL_Y,
# for my system to recognize it as mouse, WHEEL is also needed:
evdev.ecodes.REL_WHEEL,
]
if capabilities.get(ecodes.EV_KEY) is None:
capabilities[ecodes.EV_KEY] = []
# for reasons I don't know, it is required to have a capability
# for any keyboard key present to enable mouse movements.
# TODO test
# for reasons I don't know, it is also required to have
# any keyboard button in capabilities.
# TODO test that this is always present when abs_to_rel
capabilities[ecodes.EV_KEY].append(ecodes.KEY_0)
# just like what python-evdev does in from_device

@ -28,6 +28,7 @@ import evdev
from keymapper.logger import logger
from keymapper.state import KEYCODE_OFFSET
from keymapper.dev.ev_abs_mapper import JOYSTICK
def should_map_event_as_btn(type, code):
@ -47,8 +48,7 @@ def should_map_event_as_btn(type, code):
if type == evdev.events.EV_KEY:
return True
if type == evdev.events.EV_ABS and code > 5:
# 1 - 5 seem to be joystick events
if type == evdev.events.EV_ABS and code not in JOYSTICK:
return True
return False
@ -110,6 +110,5 @@ def handle_keycode(code_code_mapping, macros, event, uinput):
target_keycode = input_keycode
target_type = input_type
print('write', target_type, target_keycode, event.value)
uinput.write(target_type, target_keycode, event.value)
uinput.syn()

@ -153,7 +153,7 @@ class _KeycodeReader:
"""Get the newest tuple of event type, keycode or None."""
if self._pipe is None:
logger.debug('No pipe available to read from')
return (None, None)
return None, None
newest_event = (None, None)
while self._pipe[0].poll():

@ -38,7 +38,7 @@ CODE_3 = 102
class TestReader(unittest.TestCase):
def setUp(self):
# verify that tearDown properly cleared the reader
self.assertIsNone(keycode_reader.read())
self.assertEqual(keycode_reader.read(), (None, None))
def tearDown(self):
keycode_reader.stop_reading()

Loading…
Cancel
Save