Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions gui_agents/s1/aci/LinuxOSACI.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)})"
Expand All @@ -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; "
Expand Down
6 changes: 6 additions & 0 deletions gui_agents/s1/aci/MacOSACI.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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]
Expand Down
6 changes: 6 additions & 0 deletions gui_agents/s1/aci/WindowsOSACI.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
Expand All @@ -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]

Expand Down
27 changes: 27 additions & 0 deletions tests/test_aci_hotkey.py
Original file line number Diff line number Diff line change
@@ -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