Timer
Timer
Can't figure out how to make a timer that pops up in the bottom right hand corner on my screen that loops the numbers 0-9 where every number represents a tick. 10 ticks=6 seconds. So every time the timer hits 0, except for the first time, that means 6 seconds has pasted. Every number should have a equal value.
Re: Timer
Code: Select all
taskbar_height := 35 ; "taskbar_height := 0" for default
Gui, 99:destroy
Gui, 99: -Caption +E0x80000 +LastFound +OwnDialogs +Owner +AlwaysOnTop +E0x20
Gui, 99:Color, ceeeeee
Gui, 99:Font, s14 q1 c0xffffff
gui, 99:margin,, 0
gui, 99:add, text, vtick_display, 0
Gui, 99:Show, y-100 x-100 NoActivate, timer_string_draw
WinSet, TransColor, ceeeeee 255, timer_string_draw
WinGetPos, w_x, w_y, w_w, w_h, timer_string_draw
w_x := A_ScreenWidth - w_w
w_y := A_ScreenHeight - w_h - taskbar_height
WinMove, timer_string_draw,, %w_x%, %w_y%
current_tick := 0
SetTimer, timer, 600
return
timer:
current_tick += 1
if(current_tick>9)
current_tick := 0
GuiControl,99:, tick_display, %current_tick%
return
Re: Timer
Or the countdown version, but i can't get it to exactly 6 second (6000 milliseconds), maybe that is because there is some delay between the command. In my PC It take average 6,1 second (6.131 milliseconds) to complete.
BTW, launch it with Ctrl+J
BTW, launch it with Ctrl+J
Code: Select all
^j::
tick := 6000/10
remain_tick := 9
StartTime := A_TickCount
Gui, Countdown: New, +AlwaysOnTop -Caption, Countdown
Gui, Add, Button, gCountdownGuiClose w155, Close
Gui, Font, s30
Gui, Add, Text, vCurrent_tick x75, %remain_tick%
Gui, Font
Gui, Add, Text, vElapsed_Time x10, Elapsed Time = 0000 milliseconds
PosX := A_ScreenWidth - 180
PosY := A_ScreenHeight - 150
Gui, Show, w175 h110 x%PosX% y%PosY%
Loop, 10
{
Sleep, % tick
ElapsedTime := A_TickCount - StartTime
GuiControl, , current_tick, %remain_tick%
GuiControl, , elapsed_Time, Elapsed Time = %ElapsedTime% milliseconds
remain_tick--
}
Return
CountdownGuiClose:
ExitApp
Re: Timer
Ridwan wrote:Or the countdown version, but i can't get it to exactly 6 second (6000 milliseconds), maybe that is because there is some delay between the command. In my PC It take average 6,1 second (6.131 milliseconds) to complete.
BTW, launch it with Ctrl+J
Code: Select all
^j:: tick := 6000/10 remain_tick := 9 StartTime := A_TickCount Gui, Countdown: New, +AlwaysOnTop -Caption, Countdown Gui, Add, Button, gCountdownGuiClose w155, Close Gui, Font, s30 Gui, Add, Text, vCurrent_tick x75, %remain_tick% Gui, Font Gui, Add, Text, vElapsed_Time x10, Elapsed Time = 0000 milliseconds PosX := A_ScreenWidth - 180 PosY := A_ScreenHeight - 150 Gui, Show, w175 h110 x%PosX% y%PosY% Loop, 10 { Sleep, % tick ElapsedTime := A_TickCount - StartTime GuiControl, , current_tick, %remain_tick% GuiControl, , elapsed_Time, Elapsed Time = %ElapsedTime% milliseconds remain_tick-- } Return CountdownGuiClose: ExitApp
I tweaked your code (i get 6000 every time)
Code: Select all
^j::
tick := 6000 / 10
remain_tick := 9
Gui, Countdown: New, +AlwaysOnTop -Caption, Countdown
Gui, Add, Button, gCountdownGuiClose w155, Close
Gui, Font, s30
Gui, Add, Text, vCurrent_tick x75, %remain_tick%
Gui, Font
Gui, Add, Text, vElapsed_Time x10, Elapsed Time = 0000 milliseconds
PosX := A_ScreenWidth - 180
PosY := A_ScreenHeight - 150
Gui, Show, w175 h110 x%PosX% y%PosY%
StartTime := A_TickCount
exampleCalc := A_TickCount - StartTime
GuiControl, , current_tick, %remain_tick%
GuiControl, , elapsed_Time, Elapsed Time = %ElapsedTime% milliseconds
exampleCalc--
check_elapsed := A_TickCount - StartTime
Loop, 10
{
check_time := A_TickCount
Sleep, % tick - check_elapsed
ElapsedTime := A_TickCount - StartTime
GuiControl, , current_tick, %remain_tick%
GuiControl, , elapsed_Time, Elapsed Time = %ElapsedTime% milliseconds
remain_tick--
check_elapsed := A_TickCount - check_time - (600 - check_elapsed)
}
Return
CountdownGuiClose:
ExitApp
Re: Timer
@Qysh, that's a brilliant logic, adjusting the required sleep delay . How can i scrolling the docs for long time until i give up if just this simple is enough.
Re: Timer
Just noticed that you dont event need the example gui stuffRidwan wrote:@Qysh, that's a brilliant logic, adjusting the required sleep delay . How can i scrolling the docs for long time until i give up if just this simple is enough.
Code: Select all
^j::
tick := 6000 / 10
remain_tick := 9
Gui, Countdown: New, +AlwaysOnTop -Caption, Countdown
Gui, Add, Button, gCountdownGuiClose w155, Close
Gui, Font, s30
Gui, Add, Text, vCurrent_tick x75, %remain_tick%
Gui, Font
Gui, Add, Text, vElapsed_Time x10, Elapsed Time = 0000 milliseconds
PosX := A_ScreenWidth - 180
PosY := A_ScreenHeight - 150
Gui, Show, w175 h110 x%PosX% y%PosY%
StartTime := A_TickCount
check_elapsed := 0
Loop, 10
{
check_time := A_TickCount
Sleep, % tick - check_elapsed
ElapsedTime := A_TickCount - StartTime
GuiControl, , current_tick, %remain_tick%
GuiControl, , elapsed_Time, Elapsed Time = %ElapsedTime% milliseconds
remain_tick--
check_elapsed := A_TickCount - check_time - (600 - check_elapsed)
}
Return
CountdownGuiClose:
ExitApp
Who is online
Users browsing this forum: No registered users and 180 guests