spyoungtech / ahk

Python wrapper for AutoHotkey with full type support. Harness the automation power of AutoHotkey with the beauty of Python.
MIT License
887 stars 66 forks source link

Wrong Type of keyDelay of send command #315

Closed zzsimplezz closed 5 months ago

zzsimplezz commented 5 months ago

describe your issue

cmd: ahk.send(keyStr, key_delay=50)

Thank you for your lib. :D

ahk.version

No response

AutoHotkey version

v2

Code to reproduce the issue

# ahk v2
ahk.send("anything", key_delay=50)

Traceback/Error message

No response

spyoungtech commented 5 months ago

Thanks. Reproduced and confirmed. I should be able to have a fix out shortly.

spyoungtech commented 5 months ago

This should now be fixed in v1.7.5

Keep in mind, AutoHotkey v2 uses Input as its default SendMode. As noted in the SetKeyDelay documentation, key delay has no effect when the SendMode is Input.

So, if you're using AutoHotkey v2, you'll have to change the send mode in order to see the effect of the key_delay parameter take place properly:

from ahk import AHK
ahk = AHK(version='v2')

ahk.send('anything', key_delay=50, send_mode='Event')
# OR
ahk.set_send_mode('Event')
ahk.send('anything', key_delay=50)

Please try out the latest version and let me know if that fixes the problem or if you have any other issues. Thanks!

zzsimplezz commented 5 months ago

It seems like the method set_send_mode dont have type definition => it doesn"t show in vscode suggestion. Can you check and fix it??

spyoungtech commented 5 months ago

Hmm. @zzsimplezz The method does have type hints and I can see it properly in my PyCharm editor. I'm not sure why vscode would not show it.

The accepted arguments are the same as in AutoHotkey's SendMode.

The signature looks like this.

SendMode: TypeAlias = Literal['Event', 'Input', 'InputThenPlay', 'Play', '']  # defined in `_types.py`
def set_send_mode(self, mode: SendMode) -> None:
    ...

And can be found here for the async version and here for the sync version.

We use mypy with strict type checking, which does not allow untyped definitions and those checks also pass. My best guess is it may be a problem with vscode. If you're using a version of Python 3.10 or earlier, make sure you have typing_extensions installed in your vscode environment (though, I'm not sure why it would be missing since this is installed automatically when needed when you install ahk).