Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions evdevremapkeys/evdevremapkeys.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,7 @@ async def handle_events(
output.syn()
finally:
del registered_devices[input.path]
print(
"Unregistered: %s, %s, %s" % (input.name, input.path, input.phys),
flush=True,
)
print(f"Unregistered: {input.name} ({input.path}) {input.phys}", flush=True)
input.close()


Expand Down Expand Up @@ -302,14 +299,21 @@ def register_device(device, loop: AbstractEventLoop):
input = find_input(device)
if input is None:
return None

input.grab()

caps = input.capabilities()
# EV_SYN is automatically added to uinput devices
del caps[ecodes.EV_SYN]

remappings = device["remappings"]
extended = set(caps[ecodes.EV_KEY])
if ecodes.EV_KEY not in caps:
extended = set()
else:
extended = set(caps[ecodes.EV_KEY])

if "dummy_buttons" in device: # add dummy buttons
extended |= set(device["dummy_buttons"])

modifier_groups = []
if "modifier_groups" in device:
Expand All @@ -328,8 +332,16 @@ def flatmap(lst):
extended.update([remapping["code"]])

caps[ecodes.EV_KEY] = list(extended)
output = UInput(caps, name=device["output_name"])

extra_options = {"name": device["output_name"]}

for k, v in device.items():
if k in ["vendor", "product", "version", "bustype"]:
extra_options[k] = v

output = UInput(caps, **extra_options)
print("Registered: %s, %s, %s" % (input.name, input.path, input.phys), flush=True)

task = loop.create_task(
handle_events(input, output, remappings, modifier_groups), name=input.name
)
Expand Down
6 changes: 6 additions & 0 deletions examples/advanced_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,9 @@ devices:
- code: KEY_A
value: [1,0,1,0]
repeat: true
- input_name: "Thrustmaster T-Rudder" # Example for using rudder pedals without buttons (and a changed productid to make wine recognize it)
output_name: "T-Rudder"
product: 0x1234
dummy_buttons: [304, 305]
remappings: {}