首页 > 解决方案 > 未知问题,未输入计数器的数字

问题描述

我正在为不和谐计数器制作 AHK 脚本。没用的东西,但我正在尝试学习如何 AHK 和使用 GUI 系统。这是我第一次制作 GUI,我有一个有效的计数器代码。我想通过制作 gui 使其用户友好,以便您可以更改值。

我尝试在变量周围添加 % 和删除 % 。在这一点上,我真的很困惑。

这是我正在使用的工作非 GUI 代码

F11::Goto,lol
ESC::ExitApp,

lol:
; example add 1
VAR1 := (1)
VAR2 := (11492)

Loop,300
{
VAR2 := (VAR2+VAR1)
Send, %VAR2%
Send, {Enter}
Sleep, 6500
}
return

这是我在带有变量的 GUI 系统中使用的代码。

; Simple counter script. This is for Discord counting
Gui, Show , w210 h200, Counter

; GUI stuff
Gui, Add, Text, x20 y10 w130 Left,Input a number for delay:
Gui, Add, Text, x20 y50 w130 Left,Input a starting number:
Gui, Add, Text, x20 y90 w130 Left,Input a number to add by:
Gui, Add, Text, x20 y120 w130 Left,Input a number for the number of loops:
Gui, Add, Text, x0 y160 w200 Center,Press F11 to start the script
Gui, Add, Text, x0 y180 w200 Center,Made by Pyro#5249
Gui, Add, Edit, w50 h19 x150 y10 vDelay Left, 
Gui, Add, Edit, w50 h19 x150 y50 vSTART Left, 
Gui, Add, Edit, w50 h19 x150 y90 vADD Left,
Gui, Add, Edit, w50 h19 x150 y120 vLOOP Left,
F11::goto,lol
return

lol:
{
VAR1 := (%ADD%)
VAR2 := (%START%)

Loop,%LOOP%
{
VAR2 := (VAR2+VAR1)
Send, %VAR2%
Send, {Enter}
Sleep, %DELAY%
}
return
}

GuiClose: 
ExitApp

ESC::ExitApp,

我希望它从 F11 开始并开始列出。如

1
2
3
4
5
6
ect...

但截至目前,我什么也没得到。没结果。

标签: autohotkey

解决方案


你有一个好的开始!以下是一些应该有所帮助的事情:

  • 如果要从 GUI 获取值,则需要使用Gui , Submit. 如果您希望 Gui 保持不变,请使用NoHide选项 ( Gui , Submit , NoHide)。
  • 当您使用 分配值时:=,不使用百分比。因此,VAR := ADD将变量“ADD”的值分配给变量“VAR”。您可以使用 just 分配值,=并且您不需要使用百分号 ( VAR = %ADD%),但这仅支持旧版脚本,不建议用于新脚本。
  • 有些东西需要用大括号括起来,{}就像你对循环所做的那样,但有些东西不需要,比如“lol”标签。
  • 您可以在一个发送命令中发送多个内容,而不是将其拆分为两个单独的发送命令。

AutoHotkey 帮助文档非常好,可以很好地理解正确的语法。这是您的脚本的一个工作示例,它显示了一个消息框计数器,因为我不知道您要在哪里输入值(我已将那部分注释掉)。

; Simple counter script. This is for Discord counting
Gui, Show , w210 h200, Counter

; GUI stuff
Gui, Add, Text, x20 y10 w130 Left,Input a number for delay (ms):
Gui, Add, Text, x20 y50 w130 Left,Input a starting number:
Gui, Add, Text, x20 y90 w130 Left,Input a number to add by:
Gui, Add, Text, x20 y120 w130 Left,Input a number for the amount of loops:
Gui, Add, Text, x0 y160 w200 Center,Press F11 to start the script
Gui, Add, Text, x0 y180 w200 Center,Made by Pyro#5249
Gui, Add, Edit, w50 h19 x150 y10 vDelay Left, 
Gui, Add, Edit, w50 h19 x150 y50 vSTART Left, 
Gui, Add, Edit, w50 h19 x150 y90 vADD Left,
Gui, Add, Edit, w50 h19 x150 y120 vLOOP Left,
F11::goto,lol
return

lol:
Gui , Submit , NoHide
VAR1 := ADD
VAR2 := START

Loop , %LOOP%
{
    VAR2 += VAR1
    MsgBox ,, Counter , Counter value = %VAR2% , % DELAY / 2000
    Sleep , % DELAY / 2 ; halved delay since MsgBox is also half the delay
;    Send, %VAR2%{Enter}
;    Sleep, %DELAY%
}
return

GuiClose: 
ExitApp

推荐阅读