From afcbde5e7378589efd5f20df449cd9b8bc740eb8 Mon Sep 17 00:00:00 2001 From: Pankaj Kumar Date: Sat, 15 Mar 2025 11:02:04 +0530 Subject: [PATCH] check if keyboard file exits else exit --- src/__main__.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/__main__.py b/src/__main__.py index 96fc06d..3fded35 100755 --- a/src/__main__.py +++ b/src/__main__.py @@ -13,6 +13,11 @@ def get_device_handle(keyboard_name: str) -> libevdev.Device: """ Safely get an evdev device handle. """ + # check if the device exists by checking if the device path exists + if not os.path.exists(abs_keyboard_path(keyboard_name)): + logging.critical(f"Keyboard device {keyboard_name} not connected.") + sys.exit(0) + fd = open(abs_keyboard_path(keyboard_name), 'rb') evdev = libevdev.Device(fd) try: