fix: handle string keys in hotkey and hold_and_press - #208
Open
shotsan wants to merge 1 commit into
Open
Conversation
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'].
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #195
Code Issues
hotkey()andhold_and_press()methods located inWindowsOSACI.py,MacOSACI.py, andLinuxOSACI.py.keys,hold_keys, andpress_keysarguments 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
'enter'was passed to the_normalize_key(k) for k in keyslist comprehension, the method iterated over the string character-by-character.pyautoguiscript that strikes theEnterkey, it incorrectly generated a sequence to press the individual letters:e,n,t,e,r.The Fix
isinstance(keys, str)check at the beginning of these methods.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
tests/test_aci_hotkey.pyto ensure strings like'enter'and lists like['alt', 'tab']both compile the correctpyautoguicommands across all OS implementations.