Timer

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Mattcha
Posts: 1
Joined: 07 Oct 2016, 13:35

Timer

08 Jul 2018, 11:54

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.
Qysh
Posts: 143
Joined: 24 Apr 2018, 09:16

Re: Timer

08 Jul 2018, 13:15

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
Ridwan
Posts: 144
Joined: 17 Oct 2015, 21:06
Location: Indonesia

Re: Timer

08 Jul 2018, 15:33

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
Qysh
Posts: 143
Joined: 24 Apr 2018, 09:16

Re: Timer

09 Jul 2018, 08:58

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
Ridwan
Posts: 144
Joined: 17 Oct 2015, 21:06
Location: Indonesia

Re: Timer

09 Jul 2018, 09:21

@Qysh, that's a brilliant logic, adjusting the required sleep delay :clap: . How can i scrolling the docs for long time until i give up if just this simple is enough.
Qysh
Posts: 143
Joined: 24 Apr 2018, 09:16

Re: Timer

09 Jul 2018, 09:26

Ridwan wrote:@Qysh, that's a brilliant logic, adjusting the required sleep delay :clap: . How can i scrolling the docs for long time until i give up if just this simple is enough.
Just noticed that you dont event need the example gui stuff :D

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

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: No registered users and 180 guests