can map shoulder buttons

pull/14/head
sezanzeb 4 years ago
parent ebe0115ad0
commit f879a58363

@ -47,7 +47,8 @@ If you can't find what you need, consult
##### Gamepads ##### Gamepads
Tested with the XBOX 360 Gamepad. Joystick movements will be translated 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 ## Installation

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

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

@ -212,17 +212,19 @@ class KeycodeInjector:
if abs_to_rel: if abs_to_rel:
del capabilities[ecodes.EV_ABS] 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] = [ capabilities[ecodes.EV_REL] = [
evdev.ecodes.REL_X, evdev.ecodes.REL_X,
evdev.ecodes.REL_Y, evdev.ecodes.REL_Y,
# for my system to recognize it as mouse, WHEEL is also needed:
evdev.ecodes.REL_WHEEL, evdev.ecodes.REL_WHEEL,
] ]
if capabilities.get(ecodes.EV_KEY) is None: if capabilities.get(ecodes.EV_KEY) is None:
capabilities[ecodes.EV_KEY] = [] capabilities[ecodes.EV_KEY] = []
# for reasons I don't know, it is required to have a capability # for reasons I don't know, it is also required to have
# for any keyboard key present to enable mouse movements. # any keyboard button in capabilities.
# TODO test # TODO test that this is always present when abs_to_rel
capabilities[ecodes.EV_KEY].append(ecodes.KEY_0) capabilities[ecodes.EV_KEY].append(ecodes.KEY_0)
# just like what python-evdev does in from_device # just like what python-evdev does in from_device

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

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

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

Loading…
Cancel
Save