Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Additional action for Pressing keys #58

Open
bandophahita opened this issue Jan 15, 2025 · 1 comment
Open

Additional action for Pressing keys #58

bandophahita opened this issue Jan 15, 2025 · 1 comment

Comments

@bandophahita
Copy link
Contributor

There needs to be a way for users to press keys without specifying a target. Examples: pressing ESC, arrow keys, application hotkey intercept, etc.

I created a Press action in my suite which does the job. This is not the same thing as using Enter since there is no target to direct the send_keys.

class Press(BaseAction):
    @beat("{} tries to Press({keys})")
    def perform_as(self, actor: Actor):
        driver = actor.ability_to(BrowseTheWeb).browser
        actions = ActionChains(driver, duration=CHAIN_DURATION)
        for key in self.keys:
            actions.send_keys(key)
            if self.delay:
                actions.pause(self.delay)
        actions.perform()

    def with_delay(self, delay: float | int = 0.007) -> Self:
        self.delay = delay
        return self

    def __init__(self, *keys: str):
        self.keys = keys
        self.delay = 0.000

Before I consider creating a PR to add this into the library, it has one flaw that I feel needs addressing which is logging of keys.

Marcel tries to Press(('\ue00c',))

This really ought to read as Marcel tries to Press(<ESCAPE>) or something of the like.

@perrygoy
Copy link
Member

You may be interested to see speech_tools.KEY_NAMES and its usage in Enter.text_to_log!

Enter also currently has the alias Press, and the docstring indicates that i did mean to allow Enter/Press to be called without any Target, but it looks like while we were adding defensive code blocks we made that impossible.

Maybe the solution to this is to remove the part where we raise an exception in the "if self.target is None" block in perform_as and instead handle just pressing the key?

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

No branches or pull requests

2 participants