mirror of
https://github.com/sezanzeb/input-remapper
synced 2024-11-02 15:40:19 +00:00
mapped a D-Pad button
This commit is contained in:
parent
95b09259d3
commit
cbf97fd44c
@ -689,7 +689,7 @@
|
||||
"Shift_L", "Shift_R"
|
||||
"Alt_L", "Alt_R"
|
||||
"Control_R"
|
||||
"Mouse_1" - "Mouse_5"</property>
|
||||
"BTN_LEFT"</property>
|
||||
<property name="margin_top">5</property>
|
||||
<property name="margin_bottom">5</property>
|
||||
<property name="label" translatable="yes">Mapping</property>
|
||||
|
@ -45,7 +45,6 @@ JOYSTICK = [
|
||||
|
||||
def _write(device, ev_type, keycode, value):
|
||||
"""Inject."""
|
||||
print('move mouse', ev_type, keycode, value)
|
||||
device.write(ev_type, keycode, value)
|
||||
device.syn()
|
||||
|
||||
|
@ -202,10 +202,13 @@ class KeycodeInjector:
|
||||
if len(self.mapping) > 0 and capabilities.get(ecodes.EV_KEY) is None:
|
||||
capabilities[ecodes.EV_KEY] = []
|
||||
|
||||
for (ev_type, _), character in self.mapping:
|
||||
for (ev_type, keycode), character in self.mapping:
|
||||
if not should_map_event_as_btn(ev_type, keycode):
|
||||
continue
|
||||
|
||||
keycode = system_mapping.get(character)
|
||||
if keycode is not None:
|
||||
capabilities[ev_type].append(keycode - KEYCODE_OFFSET)
|
||||
capabilities[EV_KEY].append(keycode - KEYCODE_OFFSET)
|
||||
|
||||
if abs_to_rel:
|
||||
del capabilities[ecodes.EV_ABS]
|
||||
@ -215,6 +218,12 @@ class KeycodeInjector:
|
||||
# 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
|
||||
capabilities[ecodes.EV_KEY].append(ecodes.KEY_0)
|
||||
|
||||
# just like what python-evdev does in from_device
|
||||
if ecodes.EV_SYN in capabilities:
|
||||
@ -222,8 +231,6 @@ class KeycodeInjector:
|
||||
if ecodes.EV_FF in capabilities:
|
||||
del capabilities[ecodes.EV_FF]
|
||||
|
||||
print(capabilities)
|
||||
|
||||
return capabilities
|
||||
|
||||
async def _msg_listener(self, loop):
|
||||
@ -363,7 +370,7 @@ class KeycodeInjector:
|
||||
self.abs_state[1] = event.value
|
||||
continue
|
||||
|
||||
if should_map_event_as_btn(event):
|
||||
if should_map_event_as_btn(event.type, event.code):
|
||||
handle_keycode(code_code_mapping, macros, event, uinput)
|
||||
continue
|
||||
|
||||
|
@ -30,7 +30,7 @@ from keymapper.logger import logger
|
||||
from keymapper.state import KEYCODE_OFFSET
|
||||
|
||||
|
||||
def should_map_event_as_btn(event):
|
||||
def should_map_event_as_btn(type, code):
|
||||
"""Does this event describe a button.
|
||||
|
||||
Especially important for gamepad events, some of the buttons
|
||||
@ -38,13 +38,16 @@ def should_map_event_as_btn(event):
|
||||
|
||||
Parameters
|
||||
----------
|
||||
event : evdev.events.InputEvent
|
||||
type : int
|
||||
one of evdev.events
|
||||
code : int
|
||||
linux keycode
|
||||
"""
|
||||
# TODO test
|
||||
if event.type == evdev.events.EV_KEY:
|
||||
if type == evdev.events.EV_KEY:
|
||||
return True
|
||||
|
||||
if event.type == evdev.events.EV_ABS and event.code > 5:
|
||||
if type == evdev.events.EV_ABS and code > 5:
|
||||
# 1 - 5 seem to be joystick events
|
||||
return True
|
||||
|
||||
@ -67,6 +70,7 @@ def handle_keycode(code_code_mapping, macros, event, uinput):
|
||||
return
|
||||
|
||||
input_keycode = event.code
|
||||
input_type = event.type
|
||||
|
||||
# for logging purposes. It should log the same keycode as xev and gtk,
|
||||
# which is also displayed in the UI.
|
||||
@ -89,8 +93,9 @@ def handle_keycode(code_code_mapping, macros, event, uinput):
|
||||
|
||||
if input_keycode in code_code_mapping:
|
||||
target_keycode = code_code_mapping[input_keycode]
|
||||
target_type = evdev.events.EV_KEY
|
||||
logger.spam(
|
||||
'got code:%s value:%s event:%s, maps to code:%s',
|
||||
'got code:%s value:%s event:%s, maps to EV_KEY:%s',
|
||||
xkb_keycode,
|
||||
event.value,
|
||||
evdev.ecodes.EV[event.type],
|
||||
@ -103,7 +108,8 @@ def handle_keycode(code_code_mapping, macros, event, uinput):
|
||||
event.value,
|
||||
)
|
||||
target_keycode = input_keycode
|
||||
target_type = input_type
|
||||
|
||||
print('write', event.type, target_keycode, event.value)
|
||||
uinput.write(event.type, target_keycode, event.value)
|
||||
print('write', target_type, target_keycode, event.value)
|
||||
uinput.write(target_type, target_keycode, event.value)
|
||||
uinput.syn()
|
||||
|
@ -111,7 +111,7 @@ class _KeycodeReader:
|
||||
|
||||
# TODO write a test to map event `type 3 (EV_ABS), code 16
|
||||
# (ABS_HAT0X), value 0` to a button
|
||||
if should_map_event_as_btn(event):
|
||||
if should_map_event_as_btn(event.type, event.code):
|
||||
logger.spam(
|
||||
'got code:%s value:%s type:%s',
|
||||
event.code + KEYCODE_OFFSET,
|
||||
|
@ -27,8 +27,6 @@ gi.require_version('Gtk', '3.0')
|
||||
gi.require_version('GLib', '2.0')
|
||||
from gi.repository import Gtk, GLib
|
||||
|
||||
from evdev.ecodes import EV_KEY
|
||||
|
||||
from keymapper.state import custom_mapping
|
||||
from keymapper.logger import logger
|
||||
|
||||
@ -36,6 +34,11 @@ from keymapper.logger import logger
|
||||
CTX_KEYCODE = 2
|
||||
|
||||
|
||||
# TODO display the constant name instead of numbers.
|
||||
# displaying the event type won't be needed anymore then.
|
||||
# and the whole offset thing probably drops away
|
||||
|
||||
|
||||
class Row(Gtk.ListBoxRow):
|
||||
"""A single, configurable key mapping."""
|
||||
__gtype_name__ = 'ListBoxRow'
|
||||
|
Loading…
Reference in New Issue
Block a user