dustinisgod Posted January 7, 2022 Posted January 7, 2022 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.
Musashi Posted January 7, 2022 Posted January 7, 2022 (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 : expandcollapse popup#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 expandcollapse popup#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 January 7, 2022 by Musashi answer extended "In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."
dustinisgod Posted January 7, 2022 Author Posted January 7, 2022 (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. expandcollapse popup#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 January 7, 2022 by dustinisgod
Moderators Melba23 Posted January 7, 2022 Moderators Posted January 7, 2022 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. 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
dustinisgod Posted January 7, 2022 Author Posted January 7, 2022 A minning rig is a crypto farming machine. Nothing to do with gaming.
Moderators Melba23 Posted January 7, 2022 Moderators Posted January 7, 2022 dustinisgod, Thank you for the clarification. M23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
dustinisgod Posted January 7, 2022 Author Posted January 7, 2022 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.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now