Autohotkey if 语句不起作用
Autohotkey if statement isn't working
我在第 8 行的 if
语句不起作用。即使 %Width% 的 Msgbox
显示 3200,我总是会收到 "width is not 3200" 消息框。将 if
更改为 == 并检查“3200”而不是 3200 没有任何效果。
我还将 if
语句放在 activeMonitorInfo
方法中,它在其中显示了相同的行为。
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
activeMonitorInfo( X, Y, Width, Height )
Msgbox %Width%
if ( %Width% = 3200 ) {
msgbox "Width is 3200"
return
} else {
msgbox "Width is not 3200"
return
}
activeMonitorInfo( ByRef X, ByRef Y, ByRef Width, ByRef Height )
{
CoordMode, Mouse, Screen
MouseGetPos, mouseX , mouseY
SysGet, monCount, MonitorCount
Loop %monCount%
{
SysGet, curMon, Monitor, %a_index%
if ( mouseX >= curMonLeft and mouseX <= curMonRight and mouseY >= curMonTop and mouseY <= curMonBottom ) {
X := curMonTop
y := curMonLeft
Height := curMonBottom - curMonTop
Width := curMonRight - curMonLeft
return
}
}
}
省略百分号:
if ( Width = 3200 ) {
与
相同
if width = 3200
{
同
if(width=="3200") {
但由于某些原因,if width == 3200
或 if width = "3200"
将不起作用。我只是简单地使用了上面的第一种方法,那里不会出错。
在 Ahk 中,如果文档明确要求您提供 value
(或名称、文本、数字等),您只需要 %
s。
此外,在文字赋值中使用百分号:a = %width%
。但是,当您使用表达式赋值时不是:a := width
.
我在第 8 行的 if
语句不起作用。即使 %Width% 的 Msgbox
显示 3200,我总是会收到 "width is not 3200" 消息框。将 if
更改为 == 并检查“3200”而不是 3200 没有任何效果。
我还将 if
语句放在 activeMonitorInfo
方法中,它在其中显示了相同的行为。
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
activeMonitorInfo( X, Y, Width, Height )
Msgbox %Width%
if ( %Width% = 3200 ) {
msgbox "Width is 3200"
return
} else {
msgbox "Width is not 3200"
return
}
activeMonitorInfo( ByRef X, ByRef Y, ByRef Width, ByRef Height )
{
CoordMode, Mouse, Screen
MouseGetPos, mouseX , mouseY
SysGet, monCount, MonitorCount
Loop %monCount%
{
SysGet, curMon, Monitor, %a_index%
if ( mouseX >= curMonLeft and mouseX <= curMonRight and mouseY >= curMonTop and mouseY <= curMonBottom ) {
X := curMonTop
y := curMonLeft
Height := curMonBottom - curMonTop
Width := curMonRight - curMonLeft
return
}
}
}
省略百分号:
if ( Width = 3200 ) {
与
相同if width = 3200
{
同
if(width=="3200") {
但由于某些原因,if width == 3200
或 if width = "3200"
将不起作用。我只是简单地使用了上面的第一种方法,那里不会出错。
在 Ahk 中,如果文档明确要求您提供 value
(或名称、文本、数字等),您只需要 %
s。
此外,在文字赋值中使用百分号:a = %width%
。但是,当您使用表达式赋值时不是:a := width
.