Jump to content
Sign in to follow this  
sharpharp

Creating Countdown Timer which stays on top??

Recommended Posts

sharpharp

Hi all,

Hope somebody can help. I've coded in vbscript and hta to create a small window in the top right of a windows 7 desktop.

The hta script displays a small box with orange background in the top right hand corner of the screen, displaying a countdown time from 30 mins to 0 mins.

Problem I have is its not possible to use vbscript and hta to keep the hta timer to stay on top of all windows.

I would really appreciate it if anyone could help me achieve this with autoit. I simply need a box in the corner with a countdown timer that stays on top and cannot be closed by a user.

Thanks,

Happy to try any suggested scripts.

Sharpy

Share this post


Link to post
Share on other sites
sharpharp

http://www.google.com/search?q=site:autoitscript.com+countdown+timer

WinSetOnTop

Bon chance

Thanks, i've had a look, and this looks just like what I am after -it even stays on top of all windows :-)

#include <date.au3>

Global $afksleep, $lasth, $lastm, $lasts

$begin = Random(600000, 1500000, 1)

$afksleep = $begin

$start = TimerInit()

While $afksleep > 0

$afksleep = $begin - TimerDiff($start)

GoToBathroom()

Sleep(1000)

WEnd

ToolTip("")

Func GoToBathroom()

Local $iHours, $iMins, $iSecs

_TicksToTime($afksleep, $iHours, $iMins, $iSecs)

If $lasth <> $iHours Or $lastm <> $iMins Or $lasts <> $iSecs Then

ToolTip("Time left" & " " & $iMins & ":" & $iSecs, 0, 0)

$lasth = $iHours

$lastm = $iMins

$lasts = $iSecs

EndIf

EndFunc ;==>GoToBathroom

However I am not a good programmer at all, so would appreciate it if someone could maybe edit this to display the window on the top right hand side and change the background colour and text size, anyone able to help please?

Is it possible to make it flash when it gets down to 1 minute?

Again, any help would be appreciated.

Edited by sharpharp

Share this post


Link to post
Share on other sites
jvanegmond

We don't do script requests. The name General Help & Support implies that. "Help" is worlds apart from "Do it for you".

Share this post


Link to post
Share on other sites
sharpharp

We don't do script requests. The name General Help & Support implies that. "Help" is worlds apart from "Do it for you".

Ok, no need to be so pompous about it. Don't people help each other these days on a forum like this?

I hasten to think if you needed help in an area other than coding, how would you feel if they said no?

I would happily help anyone if it was within my means, but like i sais i'm no programmer. I can just about cobble together vbsript and hta, but have no ideas with autoit. I am not asking for a massive program, just simply a countdown timer using the code i have provided, and was hoping perhaps some of the nicer members on here could help with it.

You Manadar just need to be more helpful and less anal.

Share this post


Link to post
Share on other sites
Melba23

sharpharp,

Your script will have to change quite a bit as you cannot set a colour to a ToolTip as far as I know. So you will need a small GUI like this:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <StaticConstants.au3>
#include <Date.au3>

Global $afksleep
Global $begin = Random(6000, 150000, 1)
Global $afksleep = $begin
Global $start = TimerInit()
Global $prev = 0
Global $fcolour_toggle = True

$hGUI = GUICreate("", 100, 20, @DesktopWidth - 100, 0, BitOR($WS_POPUP, $WS_BORDER), $WS_EX_TOPMOST)
$hLabel = GUICtrlCreateLabel("", 0, 0, 100, 20, BitOr($SS_CENTER, $SS_CENTERIMAGE))
GUICtrlSetBkColor(-1, 0xFF8000)
GUISetState()

While $afksleep > 0
    $afksleep = $begin - TimerDiff($start)
    If $afksleep / 1000 <> $prev Then
        $prev = $afksleep / 1000
        GoToBathroom()
    EndIf
    Sleep(100)
WEnd

Func GoToBathroom()

    Local $iHours, $iMins, $iSecs
    _TicksToTime($afksleep, $iHours, $iMins, $iSecs)
    GUICtrlSetData($hLabel, "Time left" & " " & $iMins & ":" & StringFormat("%02i", $iSecs))
    If $iMins < 1 Then
        $fcolour_toggle =Not $fcolour_toggle
        If $fcolour_toggle Then
            GUICtrlSetBkColor($hLabel, 0xFFFF00)
        Else
            GUICtrlSetBkColor($hLabel, 0xFF8000)
        EndIf
    EndIf

EndFunc   ;==>GoToBathroom

I have seriously reduced the Random parameters to check the "flash" code - so unless you are suffering from dysentery you may find the bathroom visits a bit too frequent unless you reset them. :D

I think the rest should be self explanatory with a bit of Help file reading, but please ask if anything remains opaque even after that.

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
sharpharp

That is excellent Melba, much appreciated. (I love the flashy colours, nearly had a seizure with the choice of flashing colours :-)

Can I ask quickly, which bit of code moves the box about two inches to the left? Reason being it obscures the X and minimise buttons on open applications? Also, once the countdown reaches 0, is it easy to issue a "logoff" command on the PC?

Many thanks

Sharpy

Share this post


Link to post
Share on other sites
Melba23

sharpharp,

For the GUI position, this comes from the Help file:

GUICreate ( "title" [, width [, height [, left [, top [, style [, exStyle [, parent]]]]]]] )

And this from the script:

$hGUI = GUICreate("", 100, 20, @DesktopWidth - 100, 0, BitOR($WS_POPUP, $WS_BORDER), $WS_EX_TOPMOST)

So you should be able to work that one out on your own! :

As for logging off - try ShutDown(0). Details of this command can be found............you guessed it! :D

M23

P.S. The Help file really is very good. You are likely to get quite a lot of "unhelpful" replies if you have not even looked there first. :huggles:


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
sharpharp

M23, thanks for your help, got the window to move left a bit and the shutdown works well.

One last question, and its not in the help i checked. When the script is running, you get an AutoIT icon in the System Tray (which you can pause or exit), is there any way to hide that icon so a user cannot quit the script when it is running?

Thanks sharpy

Share this post


Link to post
Share on other sites
Melba23

sharpharp,

its not in the help i checked

Would you be willing to bet? :huggles:

Try looking for #NoTrayIcon. :D

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
sharpharp

Time for some new specs :-) Thanks for all your speedy help.

Share this post


Link to post
Share on other sites
sharpharp

Melba,

Is there any way of adjusting the "speed of the flicker rate" when it gets to below 1 minute?

I'm just thinking that the present yellow/orange flash rate is a bit too intense.?

Cheers

Edited by sharpharp

Share this post


Link to post
Share on other sites
Melba23

sharpharp,

Sure. :D

Replace the loop with this:

While $afksleep > 0
    $afksleep = $begin - TimerDiff($start)
    If Int($afksleep / 1000) <> $prev Then
        $prev = Int($afksleep / 1000)
        GoToBathroom()
    EndIf
    Sleep(100)
WEnd

The timer now flashes at 1 per sec.

Would Sir like fries with that? :huggles:

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
sharpharp

Hi, fries would be good, as long as I can have a large diet coke to go with it plz...

Script works well, having adjusted the flash speed, it is perfectly flashing at 1 flash per second when there is 1 minute left but despite all my attempts, I cannot get it to speed up the flash rate at 30 seconds, to great a sense of urgency. I tried messing with the while loop, but that effects the function below for both times.

With you being a wizard of fast food and fast scripts, any way of adjusting the script so that the flash rate is slow (as it is already), but then when it gets to 30 seconds left, the flash rate goes ballistic as we had originally?

Much appreciated,

mr maccy dee's (fry master)

Share this post


Link to post
Share on other sites
Melba23

sharpharp,

Try this - the flashing is now not quite synchronised with the time, but it does speed up at 30 secs:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <StaticConstants.au3>
#include <Date.au3>

Global $afksleep
Global $begin = Random(70000, 80000, 1)
Global $afksleep = $begin
Global $start = TimerInit()
Global $prev = 0
Global $fcolour_toggle = True

$hGUI = GUICreate("", 100, 20, @DesktopWidth - 100, 0, BitOR($WS_POPUP, $WS_BORDER), $WS_EX_TOPMOST)
$hLabel = GUICtrlCreateLabel("", 0, 0, 100, 20, BitOr($SS_CENTER, $SS_CENTERIMAGE))
GUICtrlSetBkColor(-1, 0xFF8000)
GUISetState()

While $afksleep > 0
    $afksleep = $begin - TimerDiff($start)
    Select
        Case $afksleep < 31100 And $afksleep > 31000
            AdlibRegister("_Colour_Toggle", 250) ; reduce this value to increase flash rate
        Case $afksleep < 61100 And $afksleep > 61000
            AdlibRegister("_Colour_Toggle", 1000)
    EndSelect
    If Int($afksleep / 1000) <> $prev Then
        $prev = Int($afksleep / 1000)
        GoToBathroom()
    EndIf
    Sleep(100)
WEnd


Func GoToBathroom()

    Local $iHours, $iMins, $iSecs
    _TicksToTime($afksleep, $iHours, $iMins, $iSecs)
    GUICtrlSetData($hLabel, "Time left" & " " & $iMins & ":" & StringFormat("%02i", $iSecs))

EndFunc   ;==>GoToBathroom

Func _Colour_Toggle()

    $fcolour_toggle = Not $fcolour_toggle
    If $fcolour_toggle Then
        GUICtrlSetBkColor($hLabel, 0xFFFF00)
    Else
        GUICtrlSetBkColor($hLabel, 0xFF8000)
    EndIf

EndFunc

M23

Edit:

This one is better - and synchonised again: :D

Global $afksleep
Global $begin = Random(70000, 80000, 1)
Global $afksleep = $begin
Global $start = TimerInit()
Global $prev = 0
Global $fcolour_toggle = True

$hGUI = GUICreate("", 100, 20, @DesktopWidth - 100, 0, BitOR($WS_POPUP, $WS_BORDER), $WS_EX_TOPMOST)
$hLabel = GUICtrlCreateLabel("", 0, 0, 100, 20, BitOr($SS_CENTER, $SS_CENTERIMAGE))
GUICtrlSetBkColor(-1, 0xFF8000)
GUISetState()

While $afksleep > 0
    $afksleep = $begin - TimerDiff($start)
    
    If Int($afksleep / 1000) <> $prev Then
        $prev = Int($afksleep / 1000)
        GoToBathroom()
    EndIf
    Sleep(100)
WEnd


Func GoToBathroom()

    Local $iHours, $iMins, $iSecs
    _TicksToTime($afksleep, $iHours, $iMins, $iSecs)
    GUICtrlSetData($hLabel, "Time left" & " " & $iMins & ":" & StringFormat("%02i", $iSecs))

    If $iMins < 1 Then
        If $iSecs < 30 Then
            AdlibRegister("_Colour_Toggle", 200)
        Else
            _Colour_Toggle()
        EndIf
    EndIf


EndFunc   ;==>GoToBathroom

Func _Colour_Toggle()

    $fcolour_toggle = Not $fcolour_toggle
    If $fcolour_toggle Then
        GUICtrlSetBkColor($hLabel, 0xFFFF00)
    Else
        GUICtrlSetBkColor($hLabel, 0xFF8000)
    EndIf

EndFunc

M23

Edited by Melba23

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
MegaGamerGuy

#include <WindowsConstants.au3>
#include <StaticConstants.au3>
#include <Date.au3>
Global $afksleep
Global $begin = Random(70000, 80000, 1)
Global $afksleep = $begin
Global $start = TimerInit()
Global $prev = 0
Global $fcolour_toggle = True
$hGUI = GUICreate("", 100, 20, @DesktopWidth - 100, 0, BitOR($WS_POPUP, $WS_BORDER), $WS_EX_TOPMOST)
$hLabel = GUICtrlCreateLabel("", 0, 0, 100, 20, BitOr($SS_CENTER, $SS_CENTERIMAGE))
GUICtrlSetBkColor(-1, 0xFF8000)
GUISetState()
While $afksleep > 0
    $afksleep = $begin - TimerDiff($start)
    If Int($afksleep / 1000) <> $prev Then
        $prev = Int($afksleep / 1000)
        GoToBathroom()
    EndIf
    Sleep(100)
WEnd

Func GoToBathroom()
    Local $iHours, $iMins, $iSecs
    _TicksToTime($afksleep, $iHours, $iMins, $iSecs)
    GUICtrlSetData($hLabel, "Time left" & " " & $iMins & ":" & StringFormat("%02i", $iSecs))
    If $iMins < 1 Then
        If $iSecs < 30 Then
            _Colour_Toggle()
   Sleep(125)
            _Colour_Toggle()
   Sleep(125)
            _Colour_Toggle()
   Sleep(125)
            _Colour_Toggle()
   Sleep(125)
            _Colour_Toggle()
   Sleep(125)
            _Colour_Toggle()
   Sleep(125)
            _Colour_Toggle()
   Sleep(125)
            _Colour_Toggle()
        Else
            _Colour_Toggle()
        EndIf
    EndIf

EndFunc   ;==>GoToBathroom
Func _Colour_Toggle()
    $fcolour_toggle = Not $fcolour_toggle
    If $fcolour_toggle Then
        GUICtrlSetBkColor($hLabel, 0xFFFF00)
    Else
        GUICtrlSetBkColor($hLabel, 0xFF8000)
    EndIf
EndFunc

Didn't notice date until post :oops:

Thought I'd change Melba23's last edit:

AdlibRegister("_Colour_Toggle", 200)

to

_Colour_Toggle()
   Sleep(125)
            _Colour_Toggle()
   Sleep(125)
            _Colour_Toggle()
   Sleep(125)
            _Colour_Toggle()
   Sleep(125)
            _Colour_Toggle()
   Sleep(125)
            _Colour_Toggle()
   Sleep(125)
            _Colour_Toggle()
   Sleep(125)
            _Colour_Toggle()

if it looks too tacky use:

For $i = 0 to 7
_Colour_Toggle()
Sleep(125)
Next
_Colour_Toggle()
Edited by MegaGamerGuy

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.