From a73e6b86e0a2e0f564d4ed1ddf1feebfbcaa1056 Mon Sep 17 00:00:00 2001 From: Eslam Jekso Date: Thu, 1 Feb 2024 13:30:32 +0200 Subject: [PATCH] Update send_keyevent to not give error if no device --- android_tv_rc/adb_client.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/android_tv_rc/adb_client.py b/android_tv_rc/adb_client.py index 6b26fca..5880730 100644 --- a/android_tv_rc/adb_client.py +++ b/android_tv_rc/adb_client.py @@ -760,6 +760,8 @@ def send_keyevent_input(self, keycode: KeyCodes, long_press: bool=False): keycode (KeyCode): the keycode to send, table of key codes: https://www.temblast.com/ref/akeyscode.htm long_press (bool): specify if simulate a long press for the key or not. Defaults to False. """ + if self.__selected_device is None: + return command = f'input keyevent {keycode.name}' if long_press: command += ' --longpress' @@ -775,5 +777,7 @@ def send_text_input(self, text: str, encode_spaces: bool=True): text (str): the text string to send. encode_spaces (bool): specify if spaces should be replaced by `%s` or not. Defaults to True. """ + if self.__selected_device is None: + return processed_text = text.replace(' ', '%s') if encode_spaces else text self.execute_shell_command(f'input text {processed_text}')