autohotkey - akh 文本未从 settimer 更新

标签 autohotkey

我正在尝试更改设置计时器中的文本。它不起作用。这是我想要做的伪代码

Gui, New, , Update Text Demo
gui, add, text, x20 y20 w100 h16 vtimertext, --------
Gui, show, w600 h300

TimePassed = 0

SetTimer, UpdateTime, 3000
gosub UpdateTime

Return

; The following label receives control when the user closes the GUI window.
GuiClose:
{
  ExitApp
}

Return

UpdateTime:
{
  TimePassed := (TimePassed + 1)
  TrayTip, Debug, %TimePassed%
  GuiControl,,timertext,%TimePassed%
}

Return

正如您所看到的,当从 settimer 事件调用计时器文本时,它并没有改变。

如果我做错了什么,有人可以指出吗?

谢谢。

最佳答案

我得到了 answer来自 4GForce 提交的 AHK 论坛 and SO from Jim U。我将答案放在下面以供快速引用。

Well, GuiControl,, TimerText wasn't found because it wasn't a global variable. To avoid global you need to specify the gui name. ( it was also missing the Text command ) Hope you don't mind, I changed a few things like removing your TimePassed variable

Gui MyGui:New, , % "Update Text Demo"
Gui MyGui:Add, Text, x20 y20 w100 h16 vTimerText, % "0"
Gui MyGui:Show, w600 h300
…
GuiControl, MyGui: ,timertext,%TimePassed%

基本上,发生的情况是计时器线程默认使用其自己的单独 GUI,而不是主线程中的 GUI,因此您需要命名主 GUI 并在构建它时以及在计时器中更新它时使用该名称子程序。

关于autohotkey - akh 文本未从 settimer 更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42433517/

相关文章:

windows - 如何防止Windows在按住alt键时激活按键提示?

autohotkey - 如何检测进程或应用程序是否正在运行并在没有运行时终止该程序

windows - AutoHotKey:具有多行输入的 InputBox

regex - 如何从字符串中删除电子邮件地址?

editor - 如何禁用 SciTE 中的闪烁光标?

global-variables - AutoHotkey 警告局部变量与全局变量同名

onclick - 检测单击了哪个任务栏按钮(识别目标窗口)

autohotkey - AHK 如何将变量传递给函数内的 "Run"?

function - AHK可以写函数吗?