Anyone see something wrong with this code

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
vsub
Posts: 541
Joined: 29 Sep 2015, 03:39

Anyone see something wrong with this code

09 May 2021, 14:47

Code: Select all

#SingleInstance,Force
Menu, Tray, NoStandard 
Menu, Tray, Add,Time,Time
Menu, Tray, Add,Reload,Restart
Menu, Tray, Add,Exit,Exit 
Menu, Tray, Default,Time
Menu, Tray, Icon,shell32_16771.ico
Menu, Tray,Click, 1
OnExit,Reason
InputBox,Time,Timer,Set Time in Minutes
If ErrorLevel
ExitApp
IfInString,Time,`:
{
StringSplit,Time,Time,:
Time := ((Time1 * 60)*60 + (Time2 * 60) + Time3)*1000
}
Else
Time := (Time * 60 )* 1000
Loop
{
Start := A_TickCount
Sleep,% Time
TrayTip,,Time
SoundPlay,C:\Windows\Media\Windows Background.wav,wait
KeyWait,LButton,D
SoundPlay,C:\Windows\Media\Windows Background.wav,wait
If Time != 3600000
Time = 3600000
}


Time:
ms := Time - (A_TickCount - Start)
year := A_YYYY
year += Floor(ms / 1000), SECONDS
FormatTime, Remaining, %year%, HH:mm:ss
MsgBox,,Remaining Time,% "         " Remaining,1
Return

Exit:
ExitApp

Reason:
If A_ExitReason Single
{
ms := Time - (A_TickCount - Start)
year := A_YYYY
year += Floor(ms / 1000), SECONDS
FormatTime, Remaining, %year%, HH:mm:ss
Clipboard := Remaining
ExitApp
}
Else
ExitApp

Restart:
Reload
I input minutes(usually 60 or bellow)and when the time reach 0,a tooltip appears and waits for me to left click and then it is set to 60 minutes
The problem is that sometimes the remaining time before reaching 0 becomes a lot more than 60 minutes(sometimes 15 hours or more)
I think it usually happens when I put the laptop to sleep and when I wake it up after few hours and left click,the countdown time is set to the time that has past since the last 60 minutes(when the script could not show me the tooltip because the laptop was in sleep mode))
hasantr
Posts: 933
Joined: 05 Apr 2016, 14:18
Location: İstanbul

Re: Anyone see something wrong with this code

09 May 2021, 20:20

If you are not using certain hours, you only specify it as seconds. Settimer can continue even when it is back from sleep mode. Subject as I understood what you want.
I'm not sure it'll work because I haven't tested it. I hope I did what gave the right idea.

Code: Select all

#Persistent  ; Prevent the script from exiting automatically.

InputBox,Time,Timer,Set Time in Minutes
If ErrorLevel
	ExitApp


Time := (Time * 60 )


CntTime :=0

SetTimer,Times,1
return
Times:

CntTime += 1

if(CntTime >= Time){
	CntTime :=0
	TrayTip,,Time
	SoundPlay,C:\Windows\Media\Windows Background.wav,wait
	KeyWait,LButton,D
	SoundPlay,C:\Windows\Media\Windows Background.wav,wait
	If Time != 3600000
		Time = 3600000
}
return

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Lamron750, septrinus, songdg and 270 guests