"Radio" Style buttons with a hotkey

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Vh_
Posts: 203
Joined: 17 Mar 2017, 22:06

"Radio" Style buttons with a hotkey

28 Mar 2017, 18:26

Hello,

I'm trying to get a hotkey to Stop/Start my macro. I know I can use Suspend, Toggle and have. I just want my buttons to correspond with what is. Below you can test the code, when the GUI is activated press F1 and it will disable the "Run" button. I want to be able to press F1 again, and Enable the run button but disable the stop button, as a visual indicator of the current toggle state.

Any help is appreciated. Thanks! ;)

---------------------




#SingleInstance, Force
Gui, Add, Button, x5 y10 w60 h30 gRun, Run
Gui, Add, Button, x65 y10 w60 h30 gStop, Stop
Hotkey, F1, RadioSub

Gui, Show, w130 h50, Assistant
return


Run:
Suspend, off
Control, Disable, , Button1, Assistant
Control, Enable, , Button2, Assistant
return

Stop:
Suspend, on
Control, Disable, , Button2, Assistant
Control, Enable, , Button1, Assistant
return

RadioSub:
pawse := 0

If pawse = 0
{
Control, Disable, , Button1, Assistant
Control, Enable, , Button2, Assistant
}
Else
{ Control, Disable, , Button2, Assistant
Control, Enable, , Button2, Assistant
}
return


GuiClose:
ExitApp
A_AhkUser
Posts: 1147
Joined: 06 Mar 2017, 16:18
Location: France
Contact:

Re: "Radio" Style buttons with a hotkey

28 Mar 2017, 18:48

Code: Select all

#SingleInstance, Force
pawse := false
Gui, Add, Button, x5 y10 w60 h30 gRun, Run
Gui, Add, Button, x65 y10 w60 h30 gStop, Stop
Hotkey, F1, RadioSub

Gui, Show, w130 h50, Assistant
return


Run:
Suspend, off
Control, Disable, , Button1, Assistant
Control, Enable, , Button2, Assistant
return

Stop:
Suspend, on
Control, Disable, , Button2, Assistant
Control, Enable, , Button1, Assistant
return

RadioSub:

If (pawse:=!pawse)
{
Control, Disable, , Button1, Assistant
Control, Enable, , Button2, Assistant
}
Else
{ Control, Disable, , Button2, Assistant
Control, Enable, , Button1, Assistant
}

EDIT:
In you RadioSublabel pawse always resolved to 0 just before enter in the if-statement:

Code: Select all

RadioSub:
pawse := 0

If pawse = 0
{
MsgBox, test
}
Else
{
MsgBox, this msgbox will never be displayed
}
and also you made a typo error at the last line of you script:

Control, Enable, , Button2, Assistant


Hope this helps you!
my scripts
Vh_
Posts: 203
Joined: 17 Mar 2017, 22:06

Re: "Radio" Style buttons with a hotkey

28 Mar 2017, 19:05

BEAUTIFUL <3_<3 :D

That sure did. It works!!!

Now, just to understand; I see we put the pawse := false up top and now it works. What i don't understand is, what is pawse? I just got that from somewhere on a forum to beable to do if statement with it. (pawse was my word) I think this is called a function or variable?

Thanks for the assistance, and the typo at the end ;)

Bottoms up!

Edit to post:

So after a little testing, if you manually click "Stop" (Button2) then the F1 won't work. Any ideas?

----------------
-
---------------------------
-
----------------

#NoTrayIcon
#SingleInstance, Force
pawse := false
Gui, Add, Button, x5 y10 w60 h30 gRun, Run
Gui, Add, Button, x65 y10 w60 h30 gStop, Stop
Hotkey, F1, RadioSub

Gui, Show, w130 h50, Assistant
return


Run:
Suspend, off
Control, Disable, , Button1, Assistant
Control, Enable, , Button2, Assistant
return

Stop:
Suspend, on
Control, Disable, , Button2, Assistant
Control, Enable, , Button1, Assistant
return

RadioSub:


If (pawse:=!pawse)
{
Control, Disable, , Button1, Assistant
Control, Enable, , Button2, Assistant
}
Else
{ Control, Disable, , Button2, Assistant
Control, Enable, , Button1, Assistant
}
return


GuiClose:
ExitApp
Vh_
Posts: 203
Joined: 17 Mar 2017, 22:06

Re: "Radio" Style buttons with a hotkey

28 Mar 2017, 20:23

RESOLVED: IRC CHANNEL.

Thanks, sogpotato!

Here is the winning code:

Cheers!

--------------

#SingleInstance, Force
pawse := false
Gui, Add, Button, x5 y10 w60 h30 gRadioSub , Run
Gui, Add, Button, x65 y10 w60 h30 gRadioSub, Stop

Hotkey, F1, RadioSub

Gui, Show, w130 h50, Assistant
return


q::
Msgbox,
return


RadioSub:


pawse := !pawse
Hotkey, q, toggle

If (pawse == false)
{
Control, Disable, , Button1, Assistant
Control, Enable, , Button2, Assistant

}
Else
{
Control, Disable, , Button2, Assistant
Control, Enable, , Button1, Assistant
return
}
return


GuiClose:
ExitApp

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Joey5 and 460 guests