Help coding this reminder GUI

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
AHKStudent
Posts: 1472
Joined: 05 May 2018, 12:23

Help coding this reminder GUI

Post by AHKStudent » 11 Aug 2022, 09:05

I have a gui that I set to popup as a reminder every X minutes, usually 20 minutes, it has a list of items on it. Sometimes, I manually go looking at the gui and when I do that, I want the timer to reset or else, if I look at it when the timer is at 18 minutes, it will popup two minutes later. I want it to reset every time I look at the gui to the 20 minute mark.

I wrote code and think there must be a cleaner better way to do this.

Here is a a slimmed down version of the script. Any ideas is appreciated a lot.

Code: Select all

#NoEnv
#SingleInstance Force
SetWorkingDir %A_ScriptDir%

Gui Add, Edit, x5 y5 w172 h75 vtest, Test
Gui Add, Button, x49 y85 w80 h23 gwakeUp, Remind
Gui Add, StatusBar, vst, Status Bar 
Gui Show, w183 h145, TestWake
return

wakeUp:
howLong := 25
currentTime := 0
WinMinimize, A
settimer, wu, 1000
return

wu:
if (currentTime = howLong) {
	settimer, wu, off
	return
}
if winactive("TestWake") {
	settimer, wu, off
	currentTime := 0
	WinWaitNotActive, TestWake
	guicontrol,, st, 
	SetTimer, wu, 1000
}
currentTime++
guicontrol,, st, % currentTime
return

GuiEscape:
GuiClose:
    ExitApp

User avatar
mikeyww
Posts: 26939
Joined: 09 Sep 2014, 18:38

Re: Help coding this reminder GUI

Post by mikeyww » 11 Aug 2022, 09:50

Code: Select all

mins = 20
Gui, Font, s10
Gui, Color, FFFF9E
Gui Add, Edit  , w230 r5
Gui Add, Button, wp Border, Remind
Gosub, Show
Loop {
 WinWaitNotActive, Reminder ahk_class AutoHotkeyGUI
 SetTimer, Show, % -60000 * mins
 SoundBeep, 1000
 WinWaitActive
 SoundBeep, 1500
}
Show:
Gui Show,, Reminder
Return

ButtonRemind:
Gui, Minimize
Return

Rohwedder
Posts: 7645
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Help coding this reminder GUI

Post by Rohwedder » 11 Aug 2022, 10:09

Hallo,
or, closer to your design:

Code: Select all

#NoEnv
#SingleInstance Force
SetWorkingDir %A_ScriptDir%
Gui Add, Edit, x5 y5 w172 h75 vtest, Test
Gui Add, Button, x49 y85 w80 h23 gwakeUp, Remind
Gui Add, StatusBar, vst, Status Bar
Gui Show, w183 h145, TestWake
howLong := 25
return
wakeUp:
guicontrol,, st,% currentTime := 0
WinMinimize, A
settimer, wu, 1000
return
wu:
guicontrol,, st,% ++currentTime
if (currentTime = howLong)
{
	settimer, wu, off
	WinActivate, TestWake
	currentTime := 0
}
return
GuiEscape:
GuiClose:
ExitApp

AHKStudent
Posts: 1472
Joined: 05 May 2018, 12:23

Re: Help coding this reminder GUI

Post by AHKStudent » 11 Aug 2022, 10:34

Thank you both, will use the ideas to rebuild my program :thumbup:

Post Reply

Return to “Ask for Help (v1)”