how to automate a login dialog?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
xucaen
Posts: 2
Joined: 22 Oct 2021, 09:38

how to automate a login dialog?

Post by xucaen » 22 Oct 2021, 10:02

I am trying to automate a login for work. The script runs the program but never clicks the Connect button. I'm not sure why.

Here is what I have so far:

Code: Select all

SetTitleMatchMode, 2
SetTitleMatchMode, Slow

Run, "C:\path\to\my\program.exe",, Max, PID  ;

;wait 5 seconds, the dialog is slow
SetControlDelay, 5000

;click the Connect button on the dialog that has "MY VPN Client" in the title
ControlClick, Connect, MY VPN Client

;wait 5 seconds, the dialog is slow
SetControlDelay, 5000

;send username and password to the dialog that has "Login" in the title
ControlSend, Edit, myusername{tab}, Login
ControlSend, Edit, mysecretpassword, Login

;click the OK button on the dialog that has "Login" in the title
ControlClick, OK, Login

Kind regards,
Jim

User avatar
mikeyww
Posts: 26851
Joined: 09 Sep 2014, 18:38

Re: how to automate a login dialog?

Post by mikeyww » 22 Oct 2021, 10:42

I would start with Send and Click, while your target window is active. Get that working first. After it works, you can see whether targeting an inactive window is possible.

xucaen
Posts: 2
Joined: 22 Oct 2021, 09:38

Re: how to automate a login dialog?

Post by xucaen » 22 Oct 2021, 12:40

mikeyww wrote:
22 Oct 2021, 10:42
I would start with Send and Click, while your target window is active. Get that working first. After it works, you can see whether targeting an inactive window is possible.
This was enough to get me on the right path. Script is working now. Thank you!

passing it forward. ;-)

Code: Select all

WinGet, pid, pid, My Window Name
winget, id,list,ahk_pid %pid% 
winactivate,ahk_id %id1%

;tab to the Connect button
Loop, 5
    Send {Tab}

Sleep, 20

;at this point the window was losing focus so I make it active again.
winactivate,ahk_id %id1%

;this causes the button to get pushed
Send {Enter}

;the next dialog is slow to come up, pausing for 5 seconds
Sleep, 5000

SendInput myusername
Sleep, 20
Send {Tab}
Sleep, 20
SendInput mysecretpassword
Sleep, 20

;tab to the OK button
Loop, 2
    Send {Tab}

;push that button
Send {Enter}

Post Reply

Return to “Ask for Help (v1)”