Skip to content

Commit

Permalink
Update send_keyevent to not give error if no device
Browse files Browse the repository at this point in the history
  • Loading branch information
Jekso committed Feb 1, 2024
1 parent baa7cc6 commit a73e6b8
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions android_tv_rc/adb_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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}')

0 comments on commit a73e6b8

Please sign in to comment.