Skip to content

fix: handle string keys in hotkey and hold_and_press - #208

Open
shotsan wants to merge 1 commit into
simular-ai:mainfrom
shotsan:fix/issue-195-hotkey-string-split
Open

fix: handle string keys in hotkey and hold_and_press#208
shotsan wants to merge 1 commit into
simular-ai:mainfrom
shotsan:fix/issue-195-hotkey-string-split

Conversation

@shotsan

@shotsan shotsan commented Jul 27, 2026

Copy link
Copy Markdown

Fixes #195

Code Issues

  • Target Methods: The hotkey() and hold_and_press() methods located in WindowsOSACI.py, MacOSACI.py, and LinuxOSACI.py.
  • The Problem: These methods expected the keys, hold_keys, and press_keys arguments to strictly be lists (e.g., ['enter']), but failed to enforce this or handle edge cases where a single string (e.g., 'enter') was passed by the agent.

Details of Logic Errors

  • String Iteration Bug: In Python, strings are iterable objects. When a raw string like 'enter' was passed to the _normalize_key(k) for k in keys list comprehension, the method iterated over the string character-by-character.
  • The Result: Instead of generating a pyautogui script that strikes the Enter key, it incorrectly generated a sequence to press the individual letters: e, n, t, e, r.

The Fix

  • Added an isinstance(keys, str) check at the beginning of these methods.
  • If a string is detected, it is wrapped in a list (keys = [keys]). This forces the list comprehension to iterate over the entire string as a single item, resolving the bug while maintaining backward compatibility for list inputs.

Tests Added

  • Added tests/test_aci_hotkey.py to ensure strings like 'enter' and lists like ['alt', 'tab'] both compile the correct pyautogui commands across all OS implementations.

Fixes simular-ai#195 by checking if `keys`, `hold_keys`, or `press_keys` are strings, and if so, wrapping them in a list before normalizing and joining. This prevents strings like 'enter' from being incorrectly split into ['e', 'n', 't', 'e', 'r'].
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] WindowsACI.hotkey() splits key names into individual characters

2 participants