Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
723 views
in Technique[技术] by (71.8m points)

autohotkey: sometimes button is not clicked

I wrote such autohotkey script to auto-logon my program:

SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
Run info.exe
WinWait, User identification,
Sleep 300
ControlSend, Edit1, user, User identification
ControlSend, Edit2, password, User identification
ControlClick, Button1, User identification

The problem is - sometimes Button1 is not clicked. When i'm execution script in most cases Button1 is clicked, but sometimes it doesn't. When script autoexecuted on locked workstation (this is the scenario I actually need), Button1 is never clicked.

I've tried to insert Sleep, 1000 after each line in script but it didn't helped.

The question is why, and how to fix/workaround the problem

I will try today to replace

ControlSend, Edit2, password, User identification
ControlClick, Button1, User identification

with

ControlSend, Edit2, password{Enter}, User identification

probably this will work...

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I spent a week tring to solve my problem anf finally resolved it. Hope this will help to someone.

Never try to send CAPITALIZED letter to autohotkey, instead send shiftdown and shiftup

Wrong:

ControlSend, Edit2, passworD, User identification

Right:

ControlSend, Edit2, passwor{SHIFTDOWN}d{SHIFTUP}, User identification

Also it would be better to avoid ControlClick if possible. To click a button ControlSend a Space to it.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...