diff --git a/gui_agents/s1/aci/LinuxOSACI.py b/gui_agents/s1/aci/LinuxOSACI.py index 74deaad5..09a67f3e 100644 --- a/gui_agents/s1/aci/LinuxOSACI.py +++ b/gui_agents/s1/aci/LinuxOSACI.py @@ -537,6 +537,8 @@ def hotkey(self, keys: List): Args: keys:List the keys to press in combination in a list format (e.g. ['ctrl', 'c']) """ + if isinstance(keys, str): + keys = [keys] # add quotes around the keys keys = [f"'{key}'" for key in keys] return f"import pyautogui; pyautogui.hotkey({', '.join(keys)})" @@ -548,6 +550,10 @@ def hold_and_press(self, hold_keys: List, press_keys: List): hold_keys:List, list of keys to hold press_keys:List, list of keys to press in a sequence """ + if isinstance(hold_keys, str): + hold_keys = [hold_keys] + if isinstance(press_keys, str): + press_keys = [press_keys] press_keys_str = "[" + ", ".join([f"'{key}'" for key in press_keys]) + "]" command = "import pyautogui; " diff --git a/gui_agents/s1/aci/MacOSACI.py b/gui_agents/s1/aci/MacOSACI.py index 09e70f74..d6a7423b 100644 --- a/gui_agents/s1/aci/MacOSACI.py +++ b/gui_agents/s1/aci/MacOSACI.py @@ -421,6 +421,8 @@ def hotkey(self, keys: List): Args: keys:List the keys to press in combination in a list format (e.g. ['shift', 'c']) """ + if isinstance(keys, str): + keys = [keys] # Normalize any 'cmd' to 'command' keys = [_normalize_key(k) for k in keys] # add quotes around the keys @@ -434,6 +436,10 @@ def hold_and_press(self, hold_keys: List, press_keys: List): hold_keys:List, list of keys to hold press_keys:List, list of keys to press in a sequence """ + if isinstance(hold_keys, str): + hold_keys = [hold_keys] + if isinstance(press_keys, str): + press_keys = [press_keys] # Normalize any 'cmd' to 'command' in both lists hold_keys = [_normalize_key(k) for k in hold_keys] press_keys = [_normalize_key(k) for k in press_keys] diff --git a/gui_agents/s1/aci/WindowsOSACI.py b/gui_agents/s1/aci/WindowsOSACI.py index 24b56629..3fbbbc07 100644 --- a/gui_agents/s1/aci/WindowsOSACI.py +++ b/gui_agents/s1/aci/WindowsOSACI.py @@ -405,6 +405,8 @@ def hotkey(self, keys: List[str]): Args: keys:List[str] the keys to press in combination in a list format (e.g. ['shift', 'c']) """ + if isinstance(keys, str): + keys = [keys] keys = [_normalize_key(k) for k in keys] keys = [f"'{key}'" for key in keys] command = f"import pyautogui; pyautogui.hotkey({', '.join(keys)}, interval=0.5)" @@ -417,6 +419,10 @@ def hold_and_press(self, hold_keys: List[str], press_keys: List[str]): hold_keys:List[str], list of keys to hold press_keys:List[str], list of keys to press in a sequence """ + if isinstance(hold_keys, str): + hold_keys = [hold_keys] + if isinstance(press_keys, str): + press_keys = [press_keys] hold_keys = [_normalize_key(k) for k in hold_keys] press_keys = [_normalize_key(k) for k in press_keys] diff --git a/tests/test_aci_hotkey.py b/tests/test_aci_hotkey.py new file mode 100644 index 00000000..aed0557d --- /dev/null +++ b/tests/test_aci_hotkey.py @@ -0,0 +1,27 @@ +import pytest +from gui_agents.s1.aci.WindowsOSACI import WindowsACI +from gui_agents.s1.aci.MacOSACI import MacOSACI + + +def test_windows_hotkey_single_string(): + aci = WindowsACI() + command = aci.hotkey("enter") + assert "pyautogui.hotkey('enter', interval=0.5)" in command + + +def test_windows_hotkey_list(): + aci = WindowsACI() + command = aci.hotkey(["alt", "tab"]) + assert "pyautogui.hotkey('alt', 'tab', interval=0.5)" in command + + +def test_macos_hotkey_single_string(): + aci = MacOSACI() + command = aci.hotkey("enter") + assert "pyautogui.hotkey('enter', interval=1)" in command + + +def test_macos_hotkey_list(): + aci = MacOSACI() + command = aci.hotkey(["cmd", "c"]) + assert "pyautogui.hotkey('command', 'c', interval=1)" in command