0

我在 AutoHotKey 中有一个 GUI 菜单,但我遇到了问题。GUI 有三个按钮,分别命名为“红色”、“蓝色”和“绿色”。

当用户点击说“红色”时,就会发生一个动作。如果用户点击说“蓝色”,就会发生不同的动作。

循环是用 F4 键开始的,但根据按下的按钮不同,应该循环不同的东西:红色、蓝色或绿色。

这是我到目前为止的脚本:

Gui, Add, Tab, x366 y377 w-100 h-400 , Tab1
Gui, Add, Picture, x6 y7 w320 h90 , C:\IMAGEFILEHERE
Gui, Add, Text, x46 y147 w140 h40 , Spawning Team
Gui, Add, Button, x206 y117 w120 h20 , Red
Gui, Add, Button, x206 y147 w120 h20 , Blue
Gui, Add, Button, x206 y177 w120 h20 , Green
Gui, Show, x436 y230 h208 w336, SCRIPTNAME

Loop 
{ 
  If run = 
  {
  sleep,250 
  continue
}
  Else 
  { 
if (Team = "Red") ; If Red is selected, run this part
{
    ACTION1HERE
}
if (Team = "Blue") ; If Blue is selected, run this part
{
    ACTION2HERE
}
if (Team = "Green") ; If Green is selected, run this part
{
    ACTION3HERE
}
  } 
} 
return 

F4:: 
If run =  
  run = 1 
Else 
  run = 
return


ButtonRed:
Team = Red.
MsgBox The value in the variable named Team is %Team%.
Return

ButtonBlue:
Team = Blue.
MsgBox The value in the variable named Team is %Team%.
Return

ButtonGreen:
Team = Green.
MsgBox The value in the variable named Team is %Team%.
Return

问题是 if 语句没有检测到被按下的按钮。

任何帮助深表感谢!^_^ 我对 AHK 很陌生。

4

2 回答 2

3

为每个添加按钮添加一个 gRed 、 gBlue 和 gGreen 标签,然后创建 3 个标签(转到地址)

Gui, Add, Tab, x366 y377 w-100 h-400 , Tab1
Gui, Add, Picture, x6 y7 w320 h90 , C:\IMAGEFILEHERE
Gui, Add, Text, x46 y147 w140 h40 , Spawning Team
Gui, Add, Button, x206 y117 w120 h20 gRed, Red
Gui, Add, Button, x206 y147 w120 h20 gBlue, Blue
Gui, Add, Button, x206 y177 w120 h20 gGreen, Green
Gui, Show, x436 y230 h208 w336, SCRIPTNAME

Red:
MsgBox, ACTION1HERE
Return

Blue:
MsgBox, ACTION2HERE
Return

Green:
MsgBox, ACTION3HERE
Return
于 2013-04-27T16:18:20.420 回答
0

该循环可能会阻止较低的脚本发生。改用 Settimer

所以而不是

Loop 
{ 
  If run = 
  {
  sleep,250 
  continue
}
  Else 
  { 
if (Team = "Red") ; If Red is selected, run this part
{
    ACTION1HERE
}
if (Team = "Blue") ; If Blue is selected, run this part
{
    ACTION2HERE
}
if (Team = "Green") ; If Green is selected, run this part
{
    ACTION3HERE
}
  } 
} 
return 

F4:: 
If run =  
  run = 1 
Else 
  run = 
return

尝试

F4::
If run =  
{   
  run = 1
  Settimer, actionloop, 250
}
Else 
{
  run = 
  Settimer, actionloop, off
}
return

actionloop:
  if (Team = "Red") ; If Red is selected, run this part
  {
      ACTION1HERE
  }
  if (Team = "Blue") ; If Blue is selected, run this part
  {
      ACTION2HERE
  }
  if (Team = "Green") ; If Green is selected, run this part
  {
      ACTION3HERE
  }
return 
于 2014-11-25T12:22:06.233 回答