topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • Friday March 29, 2024, 2:48 am
  • Proudly celebrating 15+ years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: simple timer  (Read 27845 times)

dbarton

  • Supporting Member
  • Joined in 2007
  • **
  • default avatar
  • Posts: 51
    • View Profile
    • Donate to Member
simple timer
« on: September 12, 2008, 02:39 PM »

I'm looking for a timer that starts with a variable that says how long to time for..

In other words.. I could have a link to it saying MYTIMER.EXE 120, and it would time for 120 mins then make a noise.
I might have another icon set up for 'MYTIMER 60' to time for one hour.

All the timers I have found requires you to start them up, then set the time you desire.

The application is to take medication 120 mins after I eat.

Paul Keith

  • Member
  • Joined in 2008
  • **
  • Posts: 1,989
    • View Profile
    • Donate to Member
Re: simple timer
« Reply #1 on: September 12, 2008, 03:33 PM »
I'm...confused but this might be what you're looking for.

TeaTimer (you're chained to Opera though)
http://widgets.opera.com/widget/6897/

WorkRave (RSI helper but you have the option to configure it to alert you to a preset time)
http://www.workrave.com/welcome/

Might be also possible to do this using a TimeBoxing software. (Didn't try this so use at your own risk. I only posted the first link I found in Google)
http://taubler.com/t...box/newuser.shtml#dl

Article on timeboxing:
http://en.wikipedia.org/wiki/Timebox

Paul Keith

  • Member
  • Joined in 2008
  • **
  • Posts: 1,989
    • View Profile
    • Donate to Member
Re: simple timer
« Reply #2 on: September 12, 2008, 04:13 PM »
I forgot, I think the default timer panel for Gnome (Linux) also does this.

belkira

  • Member
  • Joined in 2006
  • **
  • Posts: 52
    • View Profile
    • Donate to Member
Re: simple timer
« Reply #3 on: September 12, 2008, 04:55 PM »
using AutoHotKey you could do something like this:
#persistent
#singleinstance off
%1% := 60 * (%1% * 1000)

SetTimer, Message, %1%
return


Message:
SetTimer, Message, Off
msgbox Done!
ExitApp

Then just create shortcuts as needed with the appropriate time.

dbarton

  • Supporting Member
  • Joined in 2007
  • **
  • default avatar
  • Posts: 51
    • View Profile
    • Donate to Member
Re: simple timer
« Reply #4 on: September 12, 2008, 05:58 PM »
This AHK scriot looks good, but doesn't quite work 100% for me.  The time calcs may be off.. I feel silly, but I'm having a bit of trouble understanding some of it.
Any chance of breaking it down?

Any way to add a countdown by minute?
Looks like settime function may not allow that.

thanks!!
« Last Edit: September 12, 2008, 06:33 PM by dbarton »

belkira

  • Member
  • Joined in 2006
  • **
  • Posts: 52
    • View Profile
    • Donate to Member
Re: simple timer
« Reply #5 on: September 12, 2008, 06:04 PM »
Im on my way out of work now. I will try to post clearer instructions a little later tonight.

dbarton

  • Supporting Member
  • Joined in 2007
  • **
  • default avatar
  • Posts: 51
    • View Profile
    • Donate to Member
Re: simple timer
« Reply #6 on: September 12, 2008, 06:35 PM »
Im on my way out of work now. I will try to post clearer instructions a little later tonight.

I rewrote it in simpler terms to try and break it down for me, and this way make sense to me so far...
Still, I don't see how I can add a min by min countdown...

;win 2
#2::
SplashTextOn, 250, 20,, preset for 120 mins
sleep, 1000
SplashTextOff

SetTimer, Message, 7200000
return

Message:
SetTimer, Message, Off
MsgBox ,64 ,dTIMER, 120 minutes is up!
return

belkira

  • Member
  • Joined in 2006
  • **
  • Posts: 52
    • View Profile
    • Donate to Member
Re: simple timer
« Reply #7 on: September 12, 2008, 09:05 PM »
You may also want to look at this:

http://www.autohotke...ight=countdown+timer

As for my script, I think you got it but I will break it down in any case.

The way I envisioned you using it was thus:
Copy/Paste the code into a file, called say Timer.ahk. Put this file someplace out of the way, maybe the root of the C:\ drive.
Right click on this file and select Send To| Desktop (Create Shortcut).
Now right click on this file (the shortcut) go to Properties and put the number of minutes in after the Target line, i.e.:
"C:\Documents and Settings\User\Desktop\Timer.ahk" 120

This way you can create multiple timers all running at once if need be.
I will look into the countdown thing, I was thinking you only wanted something
that would tell you after a certain amount of time had passed.

The program I linked to at the beginning of this post is a countdown timer, but I don't know if
it is what you want.

Below I have explained the script. I hope it fills in any gaps I may have left.
#persistent ; Used to keep the application running long enough to use the timer
#singleinstance off ; So you can have multiple instances running
%1% := 60 * (%1% * 1000) ; Ok so this is where it gets fun, %1% is the number you give to the program (in minutes). SetTimer uses milliseconds so we have to convert that to seconds, then from there to minutes.

SetTimer, Message, %1% ; Here we tell the timer to wait for X amount of time then run the commands at the given label, in this case Message
return


Message:
SetTimer, Message, Off ; Here I turn the timer off so it doesn't keep running
msgbox Done! ; This is what happens when the timer reaches its mark.
ExitApp
-Belkira

dbarton

  • Supporting Member
  • Joined in 2007
  • **
  • default avatar
  • Posts: 51
    • View Profile
    • Donate to Member
Re: simple timer
« Reply #8 on: September 12, 2008, 09:17 PM »
Much appreciated.

I never thought of using AHK, but it seems to have worked out.. Got a version running by patches a few peoples code togther. Thanks!

belkira

  • Member
  • Joined in 2006
  • **
  • Posts: 52
    • View Profile
    • Donate to Member
Re: simple timer
« Reply #9 on: September 12, 2008, 09:24 PM »
Did you get the countdown part working also? If so I would like to see that part of the code to see how it was done.

belkira

  • Member
  • Joined in 2006
  • **
  • Posts: 52
    • View Profile
    • Donate to Member
Re: simple timer
« Reply #10 on: September 13, 2008, 12:11 AM »
Ok So I created another one with the timer showing. It shows in the form of a small tooltip box in the upper right corner of the monitor.
See if you like it, the tooltip can be moved around by playing with its coords.

;
; AutoHotkey Version: 1.x
; Language:       English
; Platform:       Win9x/NT
; Author:         A.N.Other <[email protected]>
;
; Script Function:
; Template script (you can customize this template by editing "ShellNew\Template.ahk" in your Windows folder)
;

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
#persistent
#singleinstance off
CoordMode, ToolTip, Screen
tt = %1%
time := Convert_Milliseconds(tt)
Sec := (tt * 60)

SetTimer, Message, %time%
countdown(Sec)
return


Message:
SetTimer, Message, Off
msgbox Done!
ExitApp

Convert_MilliSeconds(time,MS = 1000,M = 60)
{
return MS*M*time
}

countdown(p_count="") {
   countdown_time:=p_count
   countdown_date=16010101
   countdown_date+=%countdown_time%, s
   Loop {
      If (countdown_date >= 16010101010000){
  FormatTime, mmss, %countdown_date%, hh:mm:ss
  }else{
FormatTime, mmss, %countdown_date%, mm:ss
}
      ;msgbox %countdown_date%`n%hhmmss%
  ;//SB_SetText(mmss, 2)
      Tooltip, %mmss%, 2000,20
      Sleep, 1000
      countdown_date+=-1, s
      ;//IfLess, countdown_date, 16010101, break
      if (A_Index>countdown_time) {
         break
      }
   }
}

dbarton

  • Supporting Member
  • Joined in 2007
  • **
  • default avatar
  • Posts: 51
    • View Profile
    • Donate to Member
Re: simple timer
« Reply #11 on: September 13, 2008, 01:32 AM »
I like that countdown you have!
Which line ha sthe coordinates? I'd like lower left...

This is what I was doing:

timer=120               
Gui, Add, Button, w135 Default Vcounter END, STARTED: %timer% mins
Gui, Show, x1 y1,
SetTimer, COUNTDOWN, 60000   ; 60,000 for one minute steps
return

COUNTDOWN:
timer-=1
GuiControl,, counter, TIME LEFT: %timer% min
If timer=0
  Goto, END
Return
« Last Edit: September 13, 2008, 01:47 AM by dbarton »

belkira

  • Member
  • Joined in 2006
  • **
  • Posts: 52
    • View Profile
    • Donate to Member
Re: simple timer
« Reply #12 on: September 13, 2008, 02:53 AM »
The Coords are on this line:
Tooltip, %mmss%, 2000,20

The first number, 2000 in this case is the left right and the second number, 20, is the up down.
You can also add this line right below that line to get a "tray tip" when you hover the mouse over the icon in the tray:
Menu,Tray,Tip,Time Remaining: %mmss%
Glad you liked it!

dbarton

  • Supporting Member
  • Joined in 2007
  • **
  • default avatar
  • Posts: 51
    • View Profile
    • Donate to Member
Re: simple timer
« Reply #13 on: September 13, 2008, 03:28 AM »
I guess my next question is:

Is there a way to cancel the timer once running?
Seems like there's no X so no place for a mouse to do the cancelling.
Can't grab a key, as best I can tell..
Maybe I could mouseover the timer to get a cancel button?
Not really sure how to handle that..

Here's what i have, using your code:

#SingleInstance force
#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
#persistent
CoordMode, ToolTip, Screen
tt = %1%
;tt = 120
time := Convert_Milliseconds(tt)
Sec := (tt * 60)

SetTimer, nMessage, %time%
countdown(Sec)
return

nMessage:
SetTimer, nMessage, Off

SoundGet, volumeBackup
SoundGet, master_mute, , mute
if master_mute = on
SoundSet, +1, , mute
SoundSet, +100  ;Set it to the highest volume

Gui, +MinimizeBox
GUi, -sysmenu
gui, +toolwindow
Gui, Add, Button, w130, DONE- hit 'O' for OK
Gui, Show, x1 y1, dTIME 1.1

   SoundBeep, 500, 100
   Sleep 100
   SoundBeep, 1500, 100
   Sleep 100
   SoundBeep, 1500, 100
   Sleep 100
   SoundBeep, 1500, 100
   Sleep 100
   SoundBeep, 1500, 100
   Sleep 100
   SoundBeep, 1500, 100
   Sleep 100
   SoundBeep, 1500, 100

If master_mute = on ; Restore the volume
SoundSet, +1, , mute
soundset, %volumeBackup%

KeyWait, o, D
Tooltip ,, 2, 980
Gui Destroy
exitapp


Convert_MilliSeconds(time,MS = 1000,M = 60)
{
   return MS*M*time
}

countdown(p_count="") {
   countdown_time:=p_count
   countdown_date=16010101
   countdown_date+=%countdown_time%, s
   Loop {
      If (countdown_date >= 16010101010000){
        FormatTime, mmss, %countdown_date%, hh:mm:ss
     }else{
      FormatTime, mmss, %countdown_date%, mm:ss
      }
      ;msgbox %countdown_date%`n%hhmmss%
     ;//SB_SetText(mmss, 2)
      Tooltip, %mmss%, 2,980
      Sleep, 1000
      countdown_date+=-1, s
      ;//IfLess, countdown_date, 16010101, break
      if (A_Index>countdown_time) {
         break
      }
   }
}
« Last Edit: September 13, 2008, 03:49 AM by dbarton »

belkira

  • Member
  • Joined in 2006
  • **
  • Posts: 52
    • View Profile
    • Donate to Member
Re: simple timer
« Reply #14 on: September 13, 2008, 04:23 AM »
right now the only way to cancel once running is to right click on the tray icon and exit. You could put a hotkey in to kill it.

#e::exitapp or something like that....

dbarton

  • Supporting Member
  • Joined in 2007
  • **
  • default avatar
  • Posts: 51
    • View Profile
    • Donate to Member
Re: simple timer
« Reply #15 on: September 13, 2008, 11:21 AM »
That sounds good. Thanks.

dbarton

  • Supporting Member
  • Joined in 2007
  • **
  • default avatar
  • Posts: 51
    • View Profile
    • Donate to Member
Re: simple timer
« Reply #16 on: September 20, 2008, 06:11 PM »
deleted
« Last Edit: September 20, 2008, 06:44 PM by dbarton »

belkira

  • Member
  • Joined in 2006
  • **
  • Posts: 52
    • View Profile
    • Donate to Member
Re: simple timer
« Reply #17 on: September 20, 2008, 06:57 PM »
I was not able to get it to work either.

In looking at the AHK Help file it states that the X,Y can be expressions, but it doesn't say that they can be variables. Maybe for the X,Y on tooltip it doesn't recognize variables.....

dbarton

  • Supporting Member
  • Joined in 2007
  • **
  • default avatar
  • Posts: 51
    • View Profile
    • Donate to Member
Re: simple timer
« Reply #18 on: September 20, 2008, 07:10 PM »
Sorry I deleted my message because I found the answer.
It does accept variables, but the variable wasn't making it into the function.
It seems you need to declare that variable in the function as global.

So in my case it was just adding:

countdown(p_count="") {
global uY    <----------------------- this line
   countdown_time:=p_count
   countdown_date=16010101
   countdown_date+=%countdown_time%, s
   Loop {
      If (countdown_date >= 16010101010000){
        FormatTime, mmss, %countdown_date%, hh:mm:ss
     }else{
      FormatTime, mmss, %countdown_date%, mm:ss
      }
      ;msgbox %countdown_date%`n%hhmmss%
     ;//SB_SetText(mmss, 2)
      Tooltip, %mmss%, 2, uY
      Menu,Tray,Tip,dTIMEmini remaining: %mmss%
;   Tooltip, %uY%, 1, 1, 2
;MsgBox The value in the variable named uY is %uY%.
      Sleep, 1000
      countdown_date+=-1, s
      ;//IfLess, countdown_date, 16010101, break
      if (A_Index>countdown_time) {
Tooltip, DONE, 2,uY
         break
« Last Edit: September 20, 2008, 07:12 PM by dbarton »

cranioscopical

  • Friend of the Site
  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 4,776
    • View Profile
    • Donate to Member
Re: simple timer
« Reply #19 on: September 21, 2008, 09:02 AM »
Can you not achieve what you want by deploying the existing timer plug-in for Find And Run Robot (FARR)?
Timer plugin for FARR

dbarton

  • Supporting Member
  • Joined in 2007
  • **
  • default avatar
  • Posts: 51
    • View Profile
    • Donate to Member
Re: simple timer
« Reply #20 on: September 21, 2008, 12:16 PM »

Not sure, but the timers I have seen always set up where you have you enter the time you want *each* time you use it.
For people that take medication 2 hrs after eating every day, it's nice to have a timer that has the time value preset.

This is a preset timer, so you just hit the icon, and it counts.


czb

  • Honorary Member
  • Joined in 2007
  • **
  • Posts: 336
    • View Profile
    • My open-source online piano game
    • Donate to Member
Re: simple timer
« Reply #21 on: September 21, 2008, 12:44 PM »
Hi, if you use FARR you can link any hotkey combination to "tm in 2 0 0 take medication". So starting timer would take you to press hotkey hit enter and you are done..
My open-source online piano game: https://github.com/musicope/game

lothark

  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 13
    • View Profile
    • Donate to Member
Re: simple timer
« Reply #22 on: October 09, 2008, 09:11 AM »
You could also try EggTimer from http://www.elegantpie.com/. It remembers the last time interval.