Jump to content

How to bind a funcion to a button ?


Recommended Posts

You must specify that you are using on event mode.

Try adding this to the top of your script:

Opt ("GUIOnEventMode", 1)
It can also be done in the idle loop

While 1
   $msg = GUIGetMsg()
   Switch $Msg
      Case $Button2
         Hide()
   EndSwitch
WEnd

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

So :

#include <GUIConstants.au3>
Opt ("GUIOnEventMode", 1)

Global $Paused = 0, $IsHotkey = 0
HotKeySet("{F1}", "PauseByHotKey")
HotKeySet("{F2}", "Hide")
HotKeySet("{F3}", "Show")
HotKeySet("{F4}", "Escape")

$Button1 = GUICtrlCreateButton("Pause", 16, 16, 97, 73, 0)
$Button2 = GUICtrlCreateButton("Hide Window", 128, 16, 89, 33, 0)
$Button3 = GUICtrlCreateButton("Show Window", 128, 56, 89, 33, 0)
$Input2 = GUICtrlCreateInput("F1 = Start/Pause", 16, 120, 97, 21)
$Input3 = GUICtrlCreateInput("F2 = Hide Window", 120, 120, 97, 21)
$Input4 = GUICtrlCreateInput("F3 = Show Window", 64, 144, 113, 21)

GUISetOnEvent($GUI_EVENT_CLOSE, "Escape")
GUICtrlSetOnEvent($Button1, "Pause")
GUICtrlSetOnEvent($Button2, "Hide")
GUICtrlSetOnEvent($Button3, "Show")

GUISetState(@SW_SHOW)

While 1
   Sleep(100)
WEnd

Func PauseByHotKey()
    If $Paused Then $IsHotkey = 1
    Pause()
EndFunc

Func Pause()
    Opt("GuiOnEventMode", 0)
    GUICtrlSetData($Button1, "Start")
    $Paused = 1
    While $Paused
        Sleep(10)
        $Msg = GUIGetMsg()
        ToolTip('ScripT Is On PausE ModE',0,0)
        If $Msg = $Button1 Or $IsHotkey = 1 Then ExitLoop
    WEnd
    $IsHotkey = 0
    $Paused = 0
    ToolTip("")
    Opt("GuiOnEventMode", 1)
    GUICtrlSetData($Button1, "Pause")
EndFunc

Func Hide()
    GUISetState(@SW_HIDE)
EndFunc

Func Show()
    GUISetState(@SW_SHOW)
EndFunc

Func Escape()
    Exit
EndFunc

and :| no result , The hotkeys work but the buttons don't

Edited by trol4ever
Link to comment
Share on other sites

The code for that GUI is a bit hard on the eyes.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

humm, maybe this-

#include <GUIConstants.au3>
Opt ("GUIOnEventMode", 1)

Global $Paused = 0
HotKeySet("{F1}", "Pause")
HotKeySet("{F2}", "Hide")
HotKeySet("{F3}", "Show")
HotKeySet("{F4}", "Escape")
GUICreate("SomeGUI")

$Button1 = GUICtrlCreateButton("Pause", 16, 16, 97, 73, 0)
$Button2 = GUICtrlCreateButton("Hide Window", 128, 16, 89, 33, 0)
$Button3 = GUICtrlCreateButton("Show Window", 128, 56, 89, 33, 0)
$Input2 = GUICtrlCreateInput("F1 = Start/Pause", 16, 120, 97, 21)
$Input3 = GUICtrlCreateInput("F2 = Hide Window", 120, 120, 97, 21)
$Input4 = GUICtrlCreateInput("F3 = Show Window", 64, 144, 113, 21)

GUISetOnEvent($GUI_EVENT_CLOSE, "Escape")
GUICtrlSetOnEvent($Button1, "Pause")
GUICtrlSetOnEvent($Button2, "Hide")
GUICtrlSetOnEvent($Button3, "Show")

GUISetState(@SW_SHOW)

While 1
    Sleep(100)
    if $Paused=0 then ContinueLoop
    ToolTip('ScripT Is On PausE ModE',0,0)
WEnd

Func Pause()
    if $Paused=0 then
        GUICtrlSetData($Button1, "Start")
        $Paused = 1
    Else
        $Paused = 0
        ToolTip("")
        GUICtrlSetData($Button1, "Pause")
    EndIf
EndFunc

Func Hide()
    GUISetState(@SW_HIDE)
EndFunc

Func Show()
    GUISetState(@SW_SHOW)
EndFunc

Func Escape()
    Exit
EndFunc
Link to comment
Share on other sites

Maybe...

#include <GUIConstants.au3>
Opt ("GUIOnEventMode", 1)

Global $Paused = 1
HotKeySet("{F1}", "Pause")
HotKeySet("{F2}", "Hide")
HotKeySet("{F3}", "Show")
HotKeySet("{F4}", "Escape")
GUICreate("SomeGUI")

$Button1 = GUICtrlCreateButton("Pause", 16, 16, 97, 73, 0)
$Button2 = GUICtrlCreateButton("Hide Window", 128, 16, 89, 33, 0)
$Button3 = GUICtrlCreateButton("Show Window", 128, 56, 89, 33, 0)
$Input2 = GUICtrlCreateInput("F1 = Start/Pause", 16, 120, 97, 21)
$Input3 = GUICtrlCreateInput("F2 = Hide Window", 120, 120, 97, 21)
$Input4 = GUICtrlCreateInput("F3 = Show Window", 64, 144, 113, 21)

GUISetOnEvent($GUI_EVENT_CLOSE, "Escape")
GUICtrlSetOnEvent($Button1, "Pause")
GUICtrlSetOnEvent($Button2, "Hide")
GUICtrlSetOnEvent($Button3, "Show")

GUISetState(@SW_SHOW)

While 1
    Sleep(100)
    if $Paused=0 then ContinueLoop
    ToolTip('ScripT Is On PausE ModE',0,0)
WEnd

Func Pause()
    if $Paused=0 then
        GUICtrlSetData($Button1, "Start")
        $Paused = 1
    Else
        $Paused = 0
        ToolTip("")
        GUICtrlSetData($Button1, "Pause")
    EndIf
EndFunc

Func Hide()
    GUISetState(@SW_HIDE)
EndFunc

Func Show()
    GUISetState(@SW_SHOW)
EndFunc

Func Escape()
    Exit
EndFunc
Link to comment
Share on other sites

thx bert ... it works , but ? what have u done ? what changes u made ?

Global Paused = 1

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...