friends 0 Posted October 31, 2004 I'm stuck on how to toggle a button on (show) or off (hide) by pressing a same key ? Eg. F5 Anybody ? Share this post Link to post Share on other sites
SlimShady 1 Posted October 31, 2004 Piece of cake. Here it is: expandcollapse popup#include <GUIConstants.au3> AutoItSetOption("TrayIconDebug", 1) ;Initialize variables Global $style1 Global $IniFile Global $GUIWidth Global $GUIHeight $GUIWidth = 250 $GUIHeight = 250 $IniFile = StringTrimRight(@ScriptFullPath, 3) & "ini" ;Only a close button: ;$style1 = BitOR($WS_POPUP, $WS_CAPTION, $WS_SYSMENU) ;GUICreate("New GUI", $GUIWidth, $GUIHeight, -1, -1, $style1) HotKeySet("{F5}", "SwapButton") GUICreate("Swap Button", $GUIWidth, $GUIHeight) $button_1 = GUICtrlCreateButton("OK", 50, 150, 70, 20) GUISetState(@SW_SHOW) While 1 Sleep(25) $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE GUIDelete() Exit EndSelect WEnd Func SwapButton() If NOT IsDeclared("ButtonState") Then Global $ButtonState = "On" If $ButtonState = "On" Then $ButtonState = "Off" GUICtrlSetState($button_1, $GUI_DISABLE) ElseIf $ButtonState = "Off" Then $ButtonState = "On" GUICtrlSetState($button_1, $GUI_ENABLE) EndIf EndFunc Share this post Link to post Share on other sites
friends 0 Posted October 31, 2004 (edited) SlimShady, thanks for prompt feedback. I know you're always being a helpful guy ! Edited October 31, 2004 by friends Share this post Link to post Share on other sites
Jos 2,165 Posted October 31, 2004 (edited) Just as an alternative: You could test the current state to swap like: Func SwapButton() If GUICtrlGetState($button_1) = $GUI_ENABLE Then GUICtrlSetState($button_1, $GUI_DISABLE) Else GUICtrlSetState($button_1, $GUI_ENABLE) EndIf EndFunc Edited October 31, 2004 by JdeB SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Share this post Link to post Share on other sites
friends 0 Posted October 31, 2004 Just as an alternative: You could test the current state to swap like:Func SwapButton() If GUICtrlGetState($button_1) = $GUI_ENABLE Then GUICtrlSetState($button_1, $GUI_DISABLE) Else GUICtrlSetState($button_1, $GUI_ENABLE) EndIf EndFunc<{POST_SNAPBACK}>Thanks JdeB.... I will try it out. Share this post Link to post Share on other sites
SlimShady 1 Posted October 31, 2004 Great idea JdeB. I tried it out and it didn't work so I tried to find out why. Here's a modified version that works: Func SwapButton() If GUICtrlGetState($button_1) = $GUI_ENABLE + $GUI_SHOW Then GUICtrlSetState($button_1, $GUI_DISABLE) Else GUICtrlSetState($button_1, $GUI_ENABLE) EndIf EndFunc Share this post Link to post Share on other sites
Jos 2,165 Posted October 31, 2004 (edited) Great idea JdeB.I tried it out and it didn't work so I tried to find out why.Here's a modified version that works:Func SwapButton() If GUICtrlGetState($button_1) = $GUI_ENABLE + $GUI_SHOW Then GUICtrlSetState($button_1, $GUI_DISABLE) Else GUICtrlSetState($button_1, $GUI_ENABLE) EndIf EndFunc<{POST_SNAPBACK}>Yea... i didn't test it and didn't think of the other states it could have.This version should only test for ENABLED state only:Func SwapButton() If BitANd(GUICtrlGetState($button_1),$GUI_ENABLE) Then GUICtrlSetState($button_1, $GUI_DISABLE) Else GUICtrlSetState($button_1, $GUI_ENABLE) EndIf EndFunc Edited October 31, 2004 by JdeB SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Share this post Link to post Share on other sites