2013-04-27 53 views
0

我在AutoHotKey中有一個GUI菜單,我遇到了麻煩。 GUI有三個名爲「紅色」,「藍色」和「綠色」的按鈕。AutoHotKey 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

一個GRED,gBlue和gGreen標籤添加到每個Add按鈕,然後創建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 
+0

我徹底明白了,太感謝你了! – user2308604 2013-04-27 17:00:38

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