繁体   English   中英

autohotkey 无法读取变量 A_hour

[英]autohotkey cant read variables A_hour

这是我的第一个脚本,我希望这个脚本从 gui 中获取变量,然后它会根据变量时间 1 和时间 2 上的特定时间将 CTRL+E 发送到特定的 windows 应用程序

代码只工作到 mytimer:(第 45 行),之后 if 语句不起作用,没有显示 msgbox,有什么问题?

感谢帮助。

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

#SingleInstance,Force
;Gui Layout
;----------------------
hour:="00|01|02|03|04|05|06|07|08|09|10|11|12|13|14|15|16|17|18|19|20|21|22|23|"
minute:="00||01|02|03|04|05|06|07|08|09|10|11|12|13|14|15|16|17|18|19|20|21|22|23|24|25|26|27|28|29|30|31|32|33|34|35|36|37|38|39|40|41|42|43|44|45|46|47|48|49|50|51|52|53|54|55|56|57|58|59|"
SetTitleMatchMode,  2
SetTitleMatchMode, Fast
;Gui,Add,Text, x10, Timer control for toggle MT4 Auto Trading

Gui,Add,Text, x10, Insert your MT4 account ID :
Gui,Add,Edit, x+10 w100 vmtid
Gui,Add,Text, x10, Choose what time to toggle Auto Trading [on/off]
Gui,Add,Text, x10, Time 1 :
Gui,Add,Text, x10, Hour
Gui,Add,Text, x+50, Minutes 
Gui,Add,DropDownList, x10 w50 r10 vh1,% "16||"hour
Gui,Add,DropDownList, x+10 w50 r10 vm1,% minute

Gui,Add,Text, x10 y+10, Time 2 :
Gui,Add,Text, x10, Hour
Gui,Add,Text, x+50, Minutes 
Gui,Add,DropDownList, x10 w50 r10 vh2,% "22||"hour
Gui,Add,DropDownList, x+10 w50 r10 vm2,% minute

Gui,Add,Button, x10 y+20 w100 h50 gactive, Activate !

Gui, +AlwaysOnTop
Gui, Show, x800 y100 w300 h300, MT4 Auto Trading Timer
return

active:
Gui,Submit, NoHide
    ;MsgBox, Starting, Running Script...
#Persistent
SetTimer, mytimer, 60000
return

mytimer:
Gui, Submit, NoHide
;MsgBox, %h1%:%m1% %mtid%  ;<---only until this is working
if (A_Hour = %h1% && A_Min = %m1%)  ;<from this its not working
{

    MsgBox, wow, it h1 show
    WinActivate, %mtid%
    WinWaitActive, %mtid% 
    Send, ^e
}
if (A_Hour = %h2% && A_Min = %m2%)
{

    ;MsgBox, wow2, it h2
    WinActivate, %mtid% 
    WinWaitActive, %mtid% 
    Send, ^e
}
return


^x::ExitApp

这是使用传统语法的常见错误,而应该使用现代、更好的表达式语法

在表达式内部,这就是您在( )内部时所做的事情,您不使用引用变量的传统(将它们包装在%%中)。 相反,您只需键入变量的名称。
因此,您的 if 语句应如下所示:
if (A_Hour = h1 && A_Min = m1)

您之前所做的以及此处的其他答案所做的(在表达式语句中将变量包装在%%中)几乎是在引用指向变量的指针。
但是当指针不存在时,最终结果就是nothing
(%A_Hour% = %h1% && %A_Min% = %m1%)
评估为
("" = "" && "" = "")
这总是正确的(假设指针不存在)
可能是一个不好的解释,很难解释,但重点是,永远不要将变量包装在表达式中的%%内。

总的来说,我建议摆脱使用遗留语法。 现在已经不是 2008 年了。
我在上面链接了两次的文档页面是开始了解差异的一个很好的参考。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM