spyoungtech / ahk

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

ahk.type key delay #340

Open Apprisco opened 3 months ago

Apprisco commented 3 months ago

Checked the documentation

describe your feature request

I want AHK to type (not send) emails and passwords for example into a window. Trying to set the key_delay for this isn't working: ahk.type(account.email,key_delay=50)

Apprisco commented 3 months ago

Obviously I can replicate this with a for loop typing a single key at a time, but that seems wasteful lol.

spyoungtech commented 3 months ago

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. 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.

Try the following, which sets the send mode to Event, which will allow the key delay to take effect:

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)

When using AutoHotkey v1, this isn't necessary since Event is the default send mode in v1.

Using key delay with .type is, incidentally, not currently supported because it uses SendInput as its implementation (and, as discussed, Input send mode does not support this).