Loops 循环,使用GUI读取一条记录后停止读取(不循环)
我有一个用于在系统中输入记录的脚本,该脚本最初在MsgBox中运行良好,但我添加了一个GUI来显示记录条目。现在,脚本在第一条记录之后停止 在下面的示例中,我去掉了所有的操作和记录行,以帮助更容易地解析,但我保留了所有重要的内容,并测试了这个版本的脚本Loops 循环,使用GUI读取一条记录后停止读取(不循环),loops,user-interface,autohotkey,Loops,User Interface,Autohotkey,我有一个用于在系统中输入记录的脚本,该脚本最初在MsgBox中运行良好,但我添加了一个GUI来显示记录条目。现在,脚本在第一条记录之后停止 在下面的示例中,我去掉了所有的操作和记录行,以帮助更容易地解析,但我保留了所有重要的内容,并测试了这个版本的脚本 Loop, read, C:\_AutoHotKey\AA_test.txt { StringSplit, LineArray, A_LoopReadLine, %A_Tab% aaduedate := LineArray1
Loop, read, C:\_AutoHotKey\AA_test.txt
{
StringSplit, LineArray, A_LoopReadLine, %A_Tab%
aaduedate := LineArray1
aauniqueid := LineArray2
aaprefix := LineArray3
aasequence := LineArray4
aadescript := LineArray5
aaelig := LineArray6
;-------------------------------------------------------------------------------------
;Use these to test the file match in the Input File.
;Remove surrounding comments and surround the rest of the script up to the last brace.
SendInput, Prefix: %aaprefix% {enter}
SendInput, Sequence: %aasequence% {enter}
SendInput, Description: %aadescript% {enter}
SendInput, Eligibility: %aaelig% {enter}
SendInput, ID Card: %aaidcard% {enter}
;---------------------------------------------------------------------------------------
;Pop-up validation menu
Gui, Add, Button, x22 y380 w100 h30 , &Submit
Gui, Add, Button, x362 y380 w100 h30 , &Cancel
Gui, Font, S14 CDefault, Verdana
Gui, Add, Text, x152 y10 w210 h30 +Center, Is the entry correct?
Gui, Font, S10 CDefault, Verdana
Gui, Add, Text, x102 y40 w90 h20 , %aaprefix%
Gui, Add, Text, x102 y70 w130 h20 , %aaelig%
Gui, Add, Text, x312 y70 w30 h20 , %aadescript%
Gui, Add, Text, x432 y70 w30 h20 , %aaidcard%
Gui, Font, S8 CDefault, Verdana
Gui, Add, Text, x132 y380 w230 h40 +Center, Click Submit/press S to continue. Click cancel to stop script.
; Generated using SmartGUI Creator 4.0
Gui, Show, x9 y250 h428 w480, Auto Action Validation
Return
ButtonCancel:
ExitApp
ButtonSubmit:
Gui, Submit ;
MouseMove, 630,55
Sleep, 100
SendInput, {Click 630,55}
SendInput ^S
Return
}
按钮可以工作,单击Submit将发送MouseMove和SendInput。但在那之后,它只是停止,不加载文本文件中的下一条记录
提前谢谢 循环中有一个return命令 这将退出程序 看看这个例子。 这个循环应该运行5次,但是返回 命令在第一次运行后停止它
Loop, 5
{
msgbox, %A_Index%
return
}
我可以通过从GUI中删除submit按钮并将其移动到MsgBox来实现这一点 GUI基本上是相同的,但是Submit和Cancel行以及返回和所有逻辑都被删除了 接下来,添加了一个MsgBox来确认数据。现在,它使用GUI显示记录的内容,并使用MsgBox确认并转到下一条记录 此外,我还偷了一些代码(我真的不明白),这些代码可以移动MsgBox,这样它就不会阻塞接收应用程序中的数据输入屏幕 这是新的代码,它取代了Gui、Show、x9
OnMessage(0x44, "WM_COMMNOTIFY")
MsgBox 4, AA Entry, Would you like to continue? (press Yes or No)
WM_COMMNOTIFY(wParam) {
if (wParam = 1027) { ; AHK_DIALOG
Process, Exist
DetectHiddenWindows, On
if WinExist("ahk_class #32770 ahk_pid " . ErrorLevel) {
WinGetPos,,, w
WinMove, 90, 650
}
}
}
;If the user responds yes, then close the Gui (Destroy) and enter the record
IfMsgBox Yes
{
Gui destroy
Sleep, 100
}
else
ExitApp
}
谢谢,我希望这对其他人有所帮助。这种编程方法的问题是,如果省略了return命令,循环不会暂停。所以这也不起作用。更好的方法是编写一个函数,该函数只读取列表中的(下一个)项并键入该项。然后,您可以在循环外打开GUI,并在每次确认或不确认条目时调用此函数。这有点棘手。如果你是初学者,如果你在循环中打开一个带有“是/否”按钮的消息框,你可能会更成功。啊。射击嗯,我是一个初学者,但我还需要有记录显示供用户验证。所以,看起来我将学习如何在循环之外实现GUI。谢谢(如果您对我应该在帮助中查找的内容有任何建议,我将不胜感激。)我已经找到了如何实现这一点,并且仍然可以让GUI显示记录。我将提交和取消按钮从GUI中取出,并将MsgBox带回来。如果MsgBox的计算结果为yes,则会销毁GUI。我的下一条评论中有代码,还有一个小东西可以把消息框移到一边。