diff --git a/keymapper/getdevices.py b/keymapper/getdevices.py index 95d7890c..6bb69382 100644 --- a/keymapper/getdevices.py +++ b/keymapper/getdevices.py @@ -22,6 +22,7 @@ """Device and evdev stuff that is independent from the display server.""" +import re import multiprocessing import threading import time @@ -168,6 +169,28 @@ def classify(device): return UNKNOWN +DENYLIST = [ + ('Yubico', r'.*YubiKey.*') +] + + +def is_denylisted(device): + """Check if a device should not be used in key-mapper. + + Parameters + ---------- + device : InputDevice + """ + for vendor, name in DENYLIST: + if not re.match(vendor, str(device.info.vendor), re.IGNORECASE): + return False + + if not re.match(name, str(device.name), re.IGNORECASE): + return False + + return True + + class _GetDevices(threading.Thread): """Process to get the devices that can be worked with. @@ -217,6 +240,9 @@ class _GetDevices(threading.Thread): # skip devices that don't provide buttons that can be mapped continue + if is_denylisted(device): + continue + name = device.name path = device.path diff --git a/tests/test.py b/tests/test.py index 31a052ad..00723e7b 100644 --- a/tests/test.py +++ b/tests/test.py @@ -212,6 +212,14 @@ fixtures = { 'info': evdev.device.DeviceInfo(5, 1, 5, 1), 'name': 'key-mapper device 2' }, + + # denylisted + '/dev/input/event51': { + 'capabilities': {evdev.ecodes.EV_KEY: keyboard_keys}, + 'phys': 'usb-0000:03:00.0-5/input1', + 'info': evdev.device.DeviceInfo(6, 'YuBiCo', 6, 1), + 'name': 'fooYuBiKeYbar' + }, }