0
votes

I'm trying to sign onto my VPN with a hotkey, which means running the program, tabbing through the fields (all of them auto-populated), and pressing "Enter" once you've tabbed onto the "Submit" field.

I couldn't get it working at first (I'm very new to AHK) so I started testing it out on Notepad as I found it easier to see where things were going wrong that way. Anyway, I ended up with the following script, which works perfectly:

#!n::
Run Notepad.exe
WinActivate Untitled - Notepad
WinWaitActive Untitled - Notepad
Send {Tab 8}
Send {Enter}
return

But it's not working for my VPN. I have managed to get it working for the VPN by splitting it across two stanzas like this:

#!f::
Run [file address omitted]
return

#!o::
WinActivate [window title omitted]
WinWaitActive [window title omitted]
Send {Tab 8}
Send {Enter}
return

I'd really rather have it all encompassed in a single hotkey, though. Any advice would be appreciated!

Thanks.

1
I suspect the problem may be that your VPN takes longer to start up than Notepad, so when you get to the WinActivate, the VPN still hasn't started, so it does nothing, and thus your program hangs on the WinWaitActive. You could use a WinWait before the WinActivate to prevent this behavior. Also, from the docs, the WinWaitActive is unnecessary.Charlie Armstrong
Thank you so much! WinWait made it work. I tried removing WinWaitActive though and it broke, so I guess it is necessary sometimes!? Anyway, thanks again!dupont

1 Answers

0
votes

Thank you Charlie Armstrong for the answer! The final working code:

#!f::
Run [file address]
WinActivate [window title]
WinWait [window title]
WinWaitActive [window title]
Send {Tab 8}
Send {Enter}
return