From 032be439f80b570d59e509b63da5f36215fc1826 Mon Sep 17 00:00:00 2001 From: some1ataplace <99353321+some1ataplace@users.noreply.github.com> Date: Sat, 7 Mar 2026 07:03:01 +0000 Subject: [PATCH] Update keyboard_retrieval.py show all devices --- src/keyboard_retrieval.py | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/keyboard_retrieval.py b/src/keyboard_retrieval.py index 057a750..e3cfcb5 100644 --- a/src/keyboard_retrieval.py +++ b/src/keyboard_retrieval.py @@ -1,25 +1,34 @@ import logging import os -from typing import Final +from typing import Final, List INPUT_DEVICES_PATH: Final = '/dev/input/by-id' -_KEYBOARD_NAME_SUFFIX: Final = '-kbd' def retrieve_keyboard_name() -> str: - keyboard_devices = list(filter(lambda d: d.endswith(_KEYBOARD_NAME_SUFFIX), os.listdir(INPUT_DEVICES_PATH))) + # List all devices in the directory + all_devices = os.listdir(INPUT_DEVICES_PATH) + + keyboard_devices = [ + d for d in all_devices + ] + + # Remove duplicates just in case + keyboard_devices = list(set(keyboard_devices)) + n_devices = len(keyboard_devices) if n_devices == 0: raise ValueError(f"Couldn't find a keyboard in '{INPUT_DEVICES_PATH}'") + if n_devices == 1: logging.info(f"Found keyboard: {keyboard_devices[0]}") return keyboard_devices[0] - + # Use native Python input for user selection print("Select a device:") - for idx, device in enumerate(keyboard_devices, start=1): + for idx, device in enumerate(sorted(keyboard_devices), start=1): print(f"{idx}. {device}") - + selected_idx = -1 while selected_idx < 1 or selected_idx > n_devices: try: @@ -28,9 +37,8 @@ def retrieve_keyboard_name() -> str: print(f"Please select a number between 1 and {n_devices}") except ValueError: print("Please enter a valid number") - + return keyboard_devices[selected_idx - 1] def abs_keyboard_path(device: str) -> str: return os.path.join(INPUT_DEVICES_PATH, device) -