Skip to content

Commit

Permalink
Add support for raw event codes in mappings
Browse files Browse the repository at this point in the history
Sometimes, a device will emit an event code that doesn't have a
name in the evdev mappings. So let's allow raw numeric codes as
both the sources and targets for mappings.
  • Loading branch information
philipl committed Jan 31, 2024
1 parent 9b6f372 commit e5f2517
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions evdevremapkeys/evdevremapkeys.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ def normalize_config(remappings):
for key, mappings in remappings.items():
new_mappings = []
for mapping in mappings:
if type(mapping) is str:
if type(mapping) is str or type(mapping) is int:
new_mappings.append({'code': mapping})
else:
normalize_value(mapping)
Expand All @@ -241,11 +241,16 @@ def normalize_value(mapping):
def resolve_ecodes(by_name):
def resolve_mapping(mapping):
if 'code' in mapping:
mapping['code'] = ecodes.ecodes[mapping['code']]
code = mapping['code']
if type(code) is int:
mapping['code'] = code
else:
mapping['code'] = ecodes.ecodes[mapping['code']]
if 'type' in mapping:
mapping['type'] = ecodes.ecodes[mapping['type']]
return mapping
return {ecodes.ecodes[key]: list(map(resolve_mapping, mappings))
return {key if type(key) is int else ecodes.ecodes[key]:
list(map(resolve_mapping, mappings))
for key, mappings in by_name.items()}


Expand Down

0 comments on commit e5f2517

Please sign in to comment.