Jump to content

GUI Button and HotKey [solved]


DarkBoost
 Share

Recommended Posts

I can set a Hotkey using $Paused = Not $Paused etc. to ExitLoop if the HotKey is pressed during a loop.

I can set a GUI Button using GUIGetMsg() = $button to ExitLoop if the button is pressed during a loop.

My problem is getting them to work together so that the following can happen:

(a) Start loop with Hotkey and Stop with Button

(:graduated: Start loop with Button and Stop with HotKey

© Start/Stop loop with just the Hotkey

(d) Start/Stop loop with just the Button

This button isn't too much of a problem its just the Hotkey and started playing with @HotKeyPressed however if the HotKey is pressed once this Macro will always result = True unless I can clear this?

Any assistance would be greatly appreciated.

#include <GUIConstantsEx.au3>

Opt("MustDeclareVars", 1)

Dim $button, $button_text[3], $label, $msg

$button_text[1] = "Start"
$button_text[2] = "Stop"

HotKeySet("+~", "_RandomFunc") ;Hotkey = Shift + ~

GUICreate("Example (Shift + ~)", 300, 40)
    $button = GUICtrlCreateButton($button_text[1], 10, 10, 80, 20)
    $label = GUICtrlCreateLabel("", 100, 10, 190, 20)
GUISetState()

While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            Exit

        Case $msg = $button
            _RandomFunc()

    EndSelect
WEnd

Func _RandomFunc()
    Local $count = 0

    GUICtrlSetData($button, $button_text[2])

    While 1
        $count = $count + 1
        GUICtrlSetData($label, "Counting..." & $count)
        If @HotKeyPressed = "+~" Or GUIGetMsg() = $button Then ExitLoop
    WEnd

    GUICtrlSetData($button, $button_text[1])
EndFunc
Edited by DarkBoost
Link to comment
Share on other sites

This button isn't too much of a problem its just the Hotkey and started playing with @HotKeyPressed however if the HotKey is pressed once this Macro will always result = True unless I can clear this?

Function HotKeySet.

The name of the function to call when the key is pressed. Not specifying this parameter will unset a previous hotkey.

- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

Link to comment
Share on other sites

ok... so i look at the help file again, nope still not happening?

helpfile says this should work but... no?

#include <GUIConstantsEx.au3>

HotKeySet("+~", "_function") ;Shift + ~ to start Function

GUICreate("", 100, 100)
GUISetState()

Do
    Sleep(100)
Until GUIGetMsg() = $GUI_EVENT_CLOSE

Func _function()
    MsgBox(0, "HotKey", @HotKeyPressed)
        HotKeySet("+~")
        Send("+~")
        MsgBox(0, "HotKey", @HotKeyPressed)
    HotKeySet("+~", "_function")
EndFunc
Edited by DarkBoost
Link to comment
Share on other sites

ok... so i look at the help file again, nope still not happening?

helpfile says this should work but... no?

What do you mean "no", there's nothing wrong with that code. Also all your talk about @HotKeyPressed makes no sense. If you had spent five seconds in the helpfile you would know that it returns the "Last HotKey pressed. See the HotkeySet function".

Any assistance would be greatly appreciated.

You could do the $Paused = Not $Paused thing you mentioned earlier.

#include <GUIConstantsEx.au3>

Opt("MustDeclareVars", 1)

Dim $button, $button_text[3], $label, $msg

$button_text[1] = "Start"
$button_text[2] = "Stop"

HotKeySet("+~", "_RandomFunc") ;Hotkey = Shift + ~

GUICreate("Example (Shift + ~)", 300, 40)
$button = GUICtrlCreateButton($button_text[1], 10, 10, 80, 20)
$label = GUICtrlCreateLabel("", 100, 10, 190, 20)
GUISetState()

Global $Looping = False

While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            Exit
        Case $msg = $button
            _RandomFunc()
    EndSelect
WEnd

Func _RandomFunc()
    Local $count = 0

    $Looping = Not $Looping

    GUICtrlSetData($button, $button_text[2])

    While $Looping
        $count = $count + 1
        GUICtrlSetData($label, "Counting..." & $count)
        If GUIGetMsg() = $button Then
            $Looping = Not $Looping
            ExitLoop
        EndIf
    WEnd

    GUICtrlSetData($button, $button_text[1])
EndFunc

Something like that :graduated:

Link to comment
Share on other sites

I guess people are not understanding what I am trying to achieve as I am simply getting responses to read the help file which believe me I am well aware that its there. Just keep in mind people who post on the forum asking for help are looking for additional assistance which the help file may not be clearly providing.

This below function should be called if (1) the Hotkey (Shift + ~) is pressed or (2) the GuiButton is pressed, however it doesn't. I was looking into checking the @HotKeyPressed in way of If @HotKeyPressed = "+~" Then... however quickly realised that this Macro doesn't change until another hotkey is pressed so I was interested in how to clear @HotKeyPressed and was told to read the HelpFile however I could not find anything regarding this!?

"Please only respond if you can assist... I would like to move forward with this rather than start flame wars over a help file!"

HotKeySet("+~", "_random")
$GuiButton = GUICtrlCreateButton("Button", 10, 10, 50, 20)

Func _random()

$Paused = Not $Paused

  While $Paused
     If GUIGetMsg() = $GuiButton Then ExitLoop
  WEnd

EndFunc
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...