AutoHotKey GUI按钮发送变量

时间:2013-04-27 16:01:25

标签: variables autohotkey

我在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很新。

2 个答案:

答案 0 :(得分:3)

为每个添加按钮添加gRade蓝色和绿色标签,然后创建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

答案 1 :(得分: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 
相关问题