Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

onscreen time


  • Please log in to reply
19 replies to this topic
Cristi ®
  • Guests
  • Last active:
  • Joined: --
hi Thanh00, i know gdip is better, but i like the simple things, and yes i like to add alarm function

user2me
  • Members
  • 1 posts
  • Last active: Feb 09 2015 04:32 PM
  • Joined: 17 Dec 2011
You can use rainmeter freeware, it has lots of other options including displaying your desired text

Some other CPU related info can be displayed too on desktop, its a desktop enhancement tool

You can also customize the its scripts just like Autohotkey

Carrozza
  • Members
  • 214 posts
  • Last active: Mar 02 2016 09:51 AM
  • Joined: 05 Jul 2009
Yep, but that's not the point of posting in these forums, isn't it?

pecsabi
  • Members
  • 4 posts
  • Last active: Jun 14 2015 02:20 PM
  • Joined: 08 Aug 2014

Hi guys,

just in case, someone is interested, I added a countdown timer feature to it. Hotkeys for refresh/switch/set/pause are rCtrl-Left/Right/Up/Down.

I hope someone will find it useful.

; Thanks to tic (Tariq Porter) for his GDI+ Library, ahkscript.org/boards/viewtopic.php?t=6517
; Color picker is not working, use instead http://www.w3schools.com/tags/ref_colorpicker.asp or http://html-color-codes.info and edit the ini file yourself: cff######

#NoEnv
#include Gdip_All.ahk
DetectHiddenWindows On
SetTitleMatchMode 2
OnExit gone_away
Menu, Tray, Icon, c:\_PCs\System\Startup\AHK_Icons\Timer.ico


;---------------------- Tray menu ----------------------

Menu, Tray, click, 1
; Menu, Tray, add, Set Clock Color, set_clockcolor ; this does not work, but it is not really needed either
Menu, Tray, add, Set background opacity, set_opacity
Menu, Tray, add, Save position, save_position
Menu, Tray, add, Set click-through, click_through
Menu, Tray, add, Set always-on-top, alwaysontop
Menu, Tray, add, Set hotkeys off, hotkey_off
Menu, Tray, add
Menu, Tray, add, Alarm/Clock [rCtrl-Right], toggle_AC
Menu, Tray, add, Reset alarm [rCtrl-Up], reset_alarm
Menu, Tray, add, Pause [rCtrl-Down], toggle_pause
Menu, Tray, default, Alarm/Clock [rCtrl-Right]
Menu, Tray, add
Menu, Tray, add, Hide/Show, toggle_hide
Menu, Tray, add, Redraw [rCtrl-Left], redraw
Menu, Tray, add, Exit, gone_away
Menu, Tray, NoStandard


;---------------------- Alt+o menu ----------------------

; Menu, MyMenu, add, Set Clock Color, set_clockcolor
Menu, MyMenu, add, Set background opacity, set_opacity
Menu, MyMenu, add, Save position, save_position
Menu, MyMenu, add, Set click-through, click_through
Menu, MyMenu, add, Set always-on-top, alwaysontop
Menu, MyMenu, add, Set hotkeys off, hotkey_off
Menu, MyMenu, add
Menu, MyMenu, add, Alarm/Clock [rCtrl-Right], toggle_AC
Menu, MyMenu, add, Reset alarm [rCtrl-Up], reset_alarm
Menu, MyMenu, add, Pause [rCtrl-Down], toggle_pause
Menu, MyMenu, default, Alarm/Clock [rCtrl-Right]
Menu, MyMenu, add
Menu, MyMenu, add, Hide/Show, toggle_hide
Menu, MyMenu, add, Redraw [rCtrl-Left], redraw
Menu, MyMenu, add, Exit, gone_away
;Menu, MyMenu, NoStandard


;---------------------- create ini file ----------------------

IfNotExist, Timer.ini
{
    IniWrite, cffE9E2E2, Timer.ini, parameters, clock_color
    IniWrite, cff88F3B1, Timer.ini, parameters, clock_color1
    IniWrite, cffF38888, Timer.ini, parameters, clock_color2
    IniWrite, 100, Timer.ini, parameters, positionx
    IniWrite, 100, Timer.ini, parameters, positiony
    IniWrite, 7e, Timer.ini, parameters, opacity     ; these are hex values!
    IniWrite, 1, Timer.ini, parameters, alwaysontop
    IniWrite, 1, Timer.ini, parameters, click_through
    IniWrite, 0, Timer.ini, parameters, alarm_at_start
    IniWrite, 1:37:00, Timer.ini, parameters, def_duration
    IniWrite, -1, Timer.ini, parameters, last_count_dir
}


;---------------------- get default values ----------------------

IfExist, Timer.ini
{
    IniRead, clock_color, Timer.ini, parameters, clock_color, cffE9E2E2
    IniRead, clock_color1, Timer.ini, parameters, clock_color1, cff88F3B1
    IniRead, clock_color2, Timer.ini, parameters, clock_color2, cffF38888
    IniRead, posx, Timer.ini, parameters, positionx, 100
    IniRead, posy, Timer.ini, parameters, positiony, 100
    IniRead, opacity_value_hex, Timer.ini, parameters, opacity, 7e
    IniRead, alwaysontop, Timer.ini, parameters, alwaysontop, 1
    IniRead, click_through, Timer.ini, parameters, click_through, 1
    IniRead, alarm_at_start, Timer.ini, parameters, alarm_at_start, 0
    IniRead, def_duration, Timer.ini, parameters, def_duration, 1:37:00
    IniRead, last_duration, Timer.ini, parameters, last_duration, %def_duration%
    IniRead, last_count_dir, Timer.ini, parameters, last_count_dir, -1
    count_dir := last_count_dir
    duration := last_duration
}


;---------------------- setting up desktop clock window ----------------------

size=s24
background_color=0x%opacity_value_hex%000000
display_size:=size
 
Menu, tray, togglecheck, Set hotkeys off
Hotkey, !o, toggle
Hotkey, !i, toggle

If !pToken := Gdip_Startup()
{
    MsgBox, 48, gdiplus error!, Gdiplus failed to start. Please ensure you have gdiplus on your system
    ExitApp
}
Font = Arial
If !hFamily := Gdip_FontFamilyCreate(Font)
{
   MsgBox, 48, Font error!, The font you have specified does not exist on the system
   ExitApp
}
Gdip_DeleteFontFamily(hFamily)

Gui, 3: +E0x80000 +LastFound +OwnDialogs +Owner -caption
Gui, 3: Show, w140 h35 x0 y0 NA, i_timer
winget, hwnd1, ID, i_timer

WinWidth =140
WinHeight :=35
hbm := CreateDIBSection(WinWidth, WinHeight), hdc := CreateCompatibleDC(), obm := SelectObject(hdc, hbm)
G := Gdip_GraphicsFromHDC(hdc)
pBrush := Gdip_BrushCreateSolid(background_color)
Gdip_SetSmoothingMode(G, 4)
Gdip_FillRoundedRectangle(G, pBrush, 0, 0, WinWidth, WinHeight,10)

OnMessage(0x201, "WM_LBUTTONDOWN")
WinMove, i_timer, , %posX%, %posY%
settimer, get_realtime, 1000

if alwaysontop
    Gosub, alwaysontop

if click_through
    Gosub, click_through

WinSet, Disable,, ahk_id %hwnd1%
; When a window is disabled, the user cannot move it or interact with its controls. In addition, disabled windows are omitted from the alt-tab list.

first_reset_alarm = 1
Gosub, reset_alarm

Return

;=================== end of the main part ==================


;--------------------- reset_alarm ---------------------

reset_alarm:

if first_reset_alarm
    Goto, FirstReset

Gui, Add, Radio, vMyRadio checked, Display current time
Gui, Add, Radio,, Add
Gui, Add, Radio,, Reset to default time
Gui, Add, Radio,, Reset to last time
Gui, Add, Edit, x50 y25 vMulti, 5
Gui, Add, Text, x67 y25, times the default time
Gui, Add, Button, x10 y85 default, Next
Gui, Show
Return

ButtonNext:
{
    Gui, Submit  ; Save the input from the user to each control's associated variable.
    radioChoice = %MyRadio%
    Gui, Destroy
}

if radioChoice = 1
{
    myDurText := FormatSeconds(time_left,0)
    new_count_dir := count_dir
}
else if radioChoice = 2
{
    StringSplit, duration_array, def_duration, :
    new_time_left := time_left+Multi*(3600*duration_array1+60*duration_array2+duration_array3)
    new_count_dir := -Round(new_time_left/Abs(new_time_left))
    myDurText := FormatSeconds(new_time_left,0)
}
else if radioChoice = 3
{
    myDurText := def_duration
    new_count_dir := -1
}
else if radioChoice = 4
{
    myDurText := last_duration
    new_count_dir := last_count_dir
}

Direction := (1-new_count_dir)/2
Gui, Add, Text,, Hours:Minutes:Seconds
Gui, Add, Edit, vMyDuration, %myDurText%
Gui, Add, Checkbox, Checked%Direction% x80 y25 h20 vDirection, Count down?
Gui, Add, Text, x10, To Cancel, press Escape or close the window.
Gui, Add, Button, default, OK  ; The label ButtonOK (if it exists) will be run when the button is pressed.
Gui, Show, W290, Set timer
Return  ; End of auto-execute section. The script is idle until the user does something.

ButtonOK:
{
    Gui, Submit  ; Save the input from the user to each control's associated variable.
    count_dir := 1-2*Direction
    duration := MyDuration
    Gui, Destroy
}

FirstReset:

delay := 0
delay_start = %A_Now%
time_start := delay_start
StringSplit, duration_array, duration, :
work_time := -count_dir*(3600*duration_array1+60*duration_array2+duration_array3)
time_left := work_time

togglep := 1
Gosub, toggle_pause

alarm := 1
if first_reset_alarm
{
    alarm := alarm_at_start
    first_reset_alarm := 0
}

GuiClose:
GuiEscape:
Gui, Destroy
Return


;---------------------- redraw ----------------------

redraw:
WinGet, hwnd1, ID, i_timer
WinHide, ahk_id %hwnd1%
WinShow, ahk_id %hwnd1%
Return


;---------------------- toggle_AC ----------------------

toggle_AC:
alarm := !alarm
return


;---------------------- toggle_pause ----------------------

toggle_pause:
togglep := !togglep
if togglep
{
    delay_old := delay
    delay  = %A_Now%
    delay -= %delay_start%, seconds
    delay := delay+delay_old
}
else
{
    delay_start = %A_Now%
}
return


;---------------------- get_realtime ----------------------

get_realtime:
if !alarm
{
    if togglep
    {
        FormatTime, displaytext, %A_Now%, H . mm . ss
        time_left := CountBack(work_time,delay,time_start)
    }
    else
        FormatTime, displaytext, %A_Now%, H : mm : ss
    display_color = %clock_color%
}
else
{
    if togglep
        time_left := CountBack(work_time,delay,time_start)
    if time_left <=0
        display_color = %clock_color1%
    else
        display_color = %clock_color2%
    displaytext := FormatSeconds(time_left,1)
}
display_size = s18
gosub write_display_text_clock
return


;---------------------- write_display_text_clock ----------------------

write_display_text_clock:
Gdip_SetCompositingMode(G, 1)
Gdip_FillRoundedRectangle(G, pBrush, 0, 0, WinWidth, WinHeight, 5)
Gdip_SetCompositingMode(G, 0)
Options = x0 y6 w140 %display_color% Center %display_size%
Gdip_TextToGraphics(G, displaytext, Options, Font, winWidth, winHeight)
UpdateLayeredWindow(hwnd1, hdc, x0, y6, WinWidth, WinHeight)
return


;---------------------- click_through ----------------------

click_through:
Menu, tray, togglecheck, Set click-through
Menu, MyMenu, togglecheck, Set click-through

status := !status

if status
{
    WinGetPos, temp_x, temp_y,,, ahk_id %hwnd1%
    Gui, 3: destroy
    Gui, 3: +E0x80000 +LastFound +OwnDialogs +Owner -caption +E0x20
    Gui, 3: Show, w140 h35 x%temp_x% y%temp_y% NA, i_timer
    winget, hwnd1, ID, i_timer
    if toggle_ontop
    {
        WinSet, alwaysontop, on, ahk_id %hwnd1%
    }
}
else
{
    WinGetPos, temp_x, temp_y,,, ahk_id %hwnd1%
    Gui, 3: destroy
    Gui, 3: +E0x80000 +LastFound +OwnDialogs +Owner -caption
    Gui, 3: Show, w140 h35 x%temp_x% y%temp_y% NA, i_timer
    winget, hwnd1, ID, i_timer
    if toggle_ontop
    {
        WinSet, alwaysontop, on, ahk_id %hwnd1%
    }
}
return


;---------------------- alwaysontop ----------------------

alwaysontop:
toggle_ontop := !toggle_ontop

menu, tray, togglecheck, Set always-on-top
menu, MyMenu, togglecheck, Set always-on-top
if toggle_ontop
{
    WinSet, alwaysontop, on, ahk_id %hwnd1%
}
else
{
    WinSet, alwaysontop, off, ahk_id %hwnd1%
}
return


;---------------------- set_opacity ----------------------

set_opacity:

opacity_h := "0x" opacity_value_hex
setformat, integer, d
opacity_display := floor(opacity_h*100/255)
setformat, integer, hex

InputBox, opacity_value_dec, Transparency: 0-100, Transparency level 100 is opaque,, 300, 150,,,, 60, %opacity_display%

if opacity_value_dec not between 0 and 100
{
    msgbox error value  %opacity_value_dec% not between 0-100
    return
}
setformat, integer, hex
op := floor(opacity_value_dec*2.5)+1
StringTrimLeft, opacity_value_hex, op, 2
IniWrite, %opacity_value_hex%, Timer.ini, parameters, opacity
setformat, integer, d
Gdip_DeleteBrush(pBrush)
background_color = 0x%opacity_value_hex%000000
pBrush := Gdip_BrushCreateSolid(background_color)
return


;---------------------- enable dragwindow ----------------------
WM_LBUTTONDOWN()
{
    PostMessage, 0xA1, 2
}
return


;---------------------- my hotkeys: rCtrl - Arrows ----------------------
; you can't turn these off from the menu

>^Left::
Gosub, redraw
Return

>^Right::
Gosub, toggle_AC
Return

>^Down::
Gosub, toggle_pause
Return

>^Up::
Gosub, reset_alarm
Return


;---------------------- original hotkeys ----------------------

!i::  ; hide/show hotkey
Gosub, toggle_hide
return
~rbutton::
MouseGetPos,,, hwnd2
if (hwnd2=hwnd1)
{
    toggle=1
    WinHide, ahk_id %hwnd1%
}
return

!o::
Menu, MyMenu, show
return


;---------------------- hotkey_off ----------------------

hotkey_off:
Menu, tray, togglecheck, Set hotkeys off
Hotkey, !o, toggle
Hotkey, !i, toggle
return


;---------------------- toggle_hide ----------------------

toggle_hide:
toggle := !toggle
if toggle
{
    WinHide, ahk_id %hwnd1%
}
else
{
    WinShow, ahk_id %hwnd1%
}
return


;---------------------- save_position ----------------------

save_position:
WinGetPos, posx,posy,,, ahk_id %hwnd1%
IniWrite, %posx%, Timer.ini, parameters, positionx
IniWrite, %posy%, Timer.ini, parameters, positiony
return


;---------------------- gone_away ----------------------

gone_away:

SelectObject(hdc, obm)
DeleteObject(hbm)
DeleteDC(hdc)
Gdip_DeleteGraphics(G)
Gdip_DeleteBrush(pBrush)
Gdip_Shutdown(pToken)

last_duration := FormatSeconds(time_left,0)
IniWrite, %last_duration%, Timer.ini, parameters, last_duration

if (time_left > 0)
    count_dir := -1
else
    count_dir := 1
IniWrite, %count_dir%, Timer.ini, parameters, last_count_dir

ExitApp


;---------------------- FormatSeconds ----------------------

FormatSeconds(NumberOfSeconds,WantSpace)  ; Convert the specified number of seconds to hh:mm:ss format.
{
    time = 20050324
    NumberOfSeconds := Abs(NumberOfSeconds)
    time += %NumberOfSeconds%, seconds
    if WantSpace
    {
        FormatTime, mmss, %time%, mm : ss
        return NumberOfSeconds//3600 " : " mmss
    }
    else
    {
        FormatTime, mmss, %time%, mm:ss
        return NumberOfSeconds//3600 ":" mmss
    }
}



;---------------------- CountBack ----------------------

CountBack(work_time,delay,time_start)
{
    total_time := work_time+delay
    time_left := time_start
    time_left += %total_time%, seconds
    time_left -= %A_Now%, seconds
    if Round(time_left) = 0
        SoundPlay, %A_WinDir%\Media\ding.wav
    return time_left
}


;===================== commented section ====================

;set_clockcolor:
;newcolor:=ChooseColorA( 0x2255ff)
;if (newcolor<>"")
;{
;    clock_color=cff%newcolor%
;}
;IniWrite, %clock_color%,Timer.ini,parameters,clock_color
;return

; By SKAN code for choosing color http://www.autohotkey.com/forum/topic59534.html *** NOT WORKING! ***
;ChooseColorA( CR=0x0, hWnd=0x0, X=25, Y=25, Title=0, CustomColors=0, RGB=1 ) {
; Static CC, Color = "000000", S22 = "                      ", ATOU = "MultiByteToWideChar"
; If ! ( VarSetCapacity( CC ) ) {
; CCD =
; ( LTrim Join
;   24ZV47ZV8N8J808N8H8H8J808HC0C0CH80808HFFMFFIFFFFMFFGFFGFFIFFFFGFFFFFFGC020C88G8K1BH2K2A
;   01B8O43G43G68G6FG6FG73G65G43G6FG6CG6FG72G41G2H2H2H2H2H2H2H2H2H2H2H2H2H2H2H2H2H2H2M8G4DG
;   53G2H53G68G65G6CG6CG2H44G6CG67P25O4H4G8CH9GFFFFFFFF82G26G42G61G73G69G63G2H63G6FG6CG6FG7
;   2G73G3ATBH35O4HEG8CG56GDG2FFFF82X25O4G6AG8CH9GFFFFFFFF82G26G43G75G73G74G6FG6DG2H63G6FG6
;   CG6FG72G73G3APBH35O4G74G8CG1CGD102FFFF82X35O4G96G8CHEGCF02FFFF8H26G44G65G66G69G6EG65G2H
;   43G75G73G74G6FG6DG2H43G6FG6CG6FG72G73G2H3EG3ET1H35O4GA6G2CHEH1GFFFF8H4FG4BX35N34GA6G2CH
;   EH2GFFFF8H43G61G6EG63G65G6CX35N64GA6G2CHEHE04FFFF8H26G48G65G6CG7QB1H5N98H4G76G74GC602FF
;   FF82TB1H5N180104H8G74GBE02FFFF82TB1H5N98G7CG28G1AGC502FFFF82X35N2C01C8H4HEGC902FFFF8H26
;   G6FT2H25N98G97G14H9GDA02FFFF82G43G6FG6CG6FG72T25NACG97G14H9GDB02FFFF82G7CG53G26G6FG6CG6
;   9G64P2H25NC2G7EG14H9GD302FFFF82G48G75G26G65G3AS835ND8G7CG12HCGBF02FFFF81T2H25NC2G8CG14H
;   9GD402FFFF82G26G53G61G74G3AS835ND8G8AG12HCGCG2FFFF81T2H25NC2G9AG14H9GD502FFFF82G26G4CG7
;   5G6DG3AS835ND8G98G12HCGC102FFFF81T2H25NF3G7EG18H9GD602FFFF82G26G52G65G64G3AS835OD017CG1
;   2HCGC202FFFF81T2H25NF3G8CG18H9GD702FFFF82G26G47G72G65G65G6EG3AS835OD018AG12HCGC302FFFF8
;   1T2H25NF3G9AG18H9GD802FFFF82G42G6CG26G75G65G3AW835OD0198G12HCGC402FFFF81X35N98GA6G8EHEG
;   C802FFFF8H26G41G64G64G2H74G6FG2H43G75G73G74G6FG6DG2H43G6FG6CG6FG72G73O
; )
; Loop 20
;  StringReplace,CCD,CCD,% Chr(70+21-A_Index),% SubStr("000000000000000000000",A_Index),All
; Loop % VarSetCapacity(CC,StrLen(CCD)//2,0)
;  NumPut( "0x" . SubStr(CCD, 2*A_Index-1,2),CC,A_Index-1,"Char" )
; }
; Numput( &CC+100,CC,8 ), NumPut( &CC+36,CC,16 )
; IfNotEqual,CustomColors,0, Loop, Parse, CustomColors, |
; _ := (A_LoopField<>"" && A_Index<17) ? NumPut("0x" A_LoopField,CC,36+(4*(A_Index-1))) : 0
; Title ? DllCall( ATOU, Int,0,Int,0, Str,Title S22, UInt,22, UInt,&CC+122, UInt,44 ) : 0
; NumPut(Y,CC,112,"UShort"), NumPut(X,CC,110,"UShort"), NumPut(hWnd,CC,4)
; WinExist( "ahk_id" hWnd ) ? NumPut(0,CC,104) : 0
; RGB ? NumPut((((CR&0xFF)<<16)|(CR&0xFF00)|((CR&0xFF0000)>>16)),CC,12) : NumPut(CR,CC,12)
; If ! DllCall( "comdlg32\ChooseColorA", UInt,&CC ) || ErrorLevel
;      Return
; DllCall( "msvcrt\sprintf", Str,Color, Str,"%06X", UInt, RGB ? ( (((CR:=Numget(CC,12) )
;  &0xFF)<<16)|(CR&0xFF00)|((CR&0xFF0000)>>16)) : Numget(CC,12) )
;Return Color
;}


Godric
  • Members
  • 19 posts
  • Last active: Jun 02 2016 09:11 PM
  • Joined: 11 Nov 2013

Can you PLEASE add;

 

  1. am/pm
  2. 12h/24

 

Thank you