Jump to content

Recommended Posts

Posted

Hello,

 

First time post.

I have a simple script with a bunch of buttons that send commands to my mining rig. One of the commands on that computer takes 10 seconds to complete. I am trying to simply add a count down timer on that specific button that counts down from 10 to 0, then rests back at 10 until pressed again. I have searched the forums and found timers and all sorts of things, but I cannot find anything on this specific instance of adding it to the button itself. I am very new to all of this and slowly learning as a hobby. If someone can point me in the right direction it would be appreciated. Hopefully its not a lack of forum search skills.

Thank you.

Posted (edited)

 

1 hour ago, dustinisgod said:

If someone can point me in the right direction it would be appreciated. Hopefully its not a lack of forum search skills.

For example, here is an older script by @Melba23 that might inspire you ;):

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <MsgBoxConstants.au3>

$fReboot = True

$Form1 = GUICreate("You have to reboot", 362, 128, 192, 124, BitOR($WS_SYSMENU, $WS_POPUP, $WS_BORDER, $WS_CAPTION))
$Label1 = GUICtrlCreateLabel("You have to Reboot your machine now for changes to take effect.", 16, 32, 327, 17)
$Button1 = GUICtrlCreateButton("OK (10)", 64, 80, 75, 25)
$Button2 = GUICtrlCreateButton("Cancel", 200, 80, 75, 25)
GUISetState(@SW_SHOW)

$iSec = @SEC
$iCount = 10

While 1

    If @SEC <> $iSec Then
        $iSec = @SEC
        $iCount -= 1
        If Not $iCount Then
            ExitLoop ; Exit if counter reaches 0
        EndIf
        GUICtrlSetData($Button1, "OK (" & ($iCount) & ")") ; Refreshes the Button 1 caption to display the countdown
        ;Sleep(10)                                              ; Not needed with a GUIGetMsg in the loop
    EndIf

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE, $Button1
            ExitLoop
        Case $Button2
            $fReboot = False
            ExitLoop
    EndSwitch

WEnd

GUIDelete($Form1)

If $fReboot Then
    MsgBox($MB_SYSTEMMODAL, "Warning", "Rebooting")
Else
    MsgBox($MB_SYSTEMMODAL, "Cancel", "You have cancelled the reboot")
EndIf

 

EDIT : @dustinisgod : Also useful might be this script (by Melba23) : countdown-button

#include <GUIConstantsEx.au3>

; You will need to reset this to 30
$iCount = 5

$hGUI = GUICreate("Test", 500, 500)

$hButton = GUICtrlCreateButton($iCount, 10, 10, 80, 30)

GUISetState()

; Get a timestamp
$iBegin = TimerInit()

While 1

    ; If it is over a second since the timestamp
    If TimerDiff($iBegin) > 1000 Then
        ; Reduce the count
        $iCount -= 1
        ; Are we timed out?
        If $iCount = -1 Then
            ; Exit the loop
            ExitLoop
        Else
            ; Change the button text
            GUICtrlSetData($hButton, $iCount)
        EndIf
        ; reset teh timestamp for the next second
        $iBegin = TimerInit()
    EndIf

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $hButton
            ; Exit the loop if the button was pressed
            ExitLoop
    EndSwitch

WEnd

; Now see the value of count
If $iCount = -1 Then
    MsgBox(0, "Countdown", "Timed out")
Else
    MsgBox(0, "Countdown", "Button pressed")
EndIf

 

Edited by Musashi
answer extended

Musashi-C64.png

"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."

Posted (edited)

Musashi,

 

Thanks for the replies. I Combined both of those. And I started out no where close. But after some trial and error.. I am closer.. I think. The script will now count down in the button from 10 to 1. But then it stops at 1. It will also now reset to 10 but only if I click on it again, instead of it automatically resetting once it reaches 0.

Incoming newbie code, bare with me. I shrunk it down to 1 button for an easier to deal with snippet.

 

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <MsgBoxConstants.au3>
#include <WinAPISysWin.au3>
#include <GUIConstants.au3>
#include <GDIPlus.au3>
#include <WinAPISys.au3>
#include <SendMessage.au3>


$iBegin = TimerInit()
$iCount = 10

#Region ### START Koda GUI section ### Form=C:\Users\dusti\Downloads\Hotbar_Leckses\Form1.kxf
$Form1 = GUICreate("Form1", 80, 321, 740, 1071, $WS_POPUP, $WS_EX_TOPMOST)
$Button1 = GUICtrlCreateButton("CH1 (" & ($iCount) & ")", 0, 0, 43, 27)

GUISetBkColor(0x005A00)
GUISetState(@SW_SHOWNOACTIVATE)
#EndRegion ### END Koda GUI section ###

While 1

    $msg = GUIGetMsg()
    Select
         Case $msg = $Button1
            $message = "SEND FUNCTION: " & GUICtrlRead($Button1)


         While 1
            If TimerDiff($iBegin) > 1000 Then
                  $iCount -= 1
                  $iBegin = TimerInit()
               Else
               GUICtrlSetData($Button1, "CH1 (" & ($iCount) & ")")
            EndIf

            If $iCount = 0 Then
               $iCount = 10
                  ExitLoop
            EndIf
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1

            ExitLoop
    EndSwitch

         WEnd


    EndSelect
 WEnd

 

Edited by dustinisgod
  • Moderators
Posted

dustinisgod,

Quote

buttons that send commands to my mining rig

Does that mean this is for a game? If so, you appear to have missed the Forum rules on your way in. Please read them now - particularly the bit about not discussing game automation.

M23

P.S. And just to be absolutely clear - this is the Mod team determining the legality of the thread, so everyone else please keep out.

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

  • Moderators
Posted

dustinisgod,

Thank you for the clarification.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Posted

No problem. I am trying to automate some of the process's I currently have to walk to my mining shed and input manually, by being able to remotely do them from my house pc with a click. So far its going ok, just new to all of this, so you know. Takes time.

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
  • Recently Browsing   0 members

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