[jawsscripts] Re: simple timer/countdown script

  • From: "Paul Magill" <magills@xxxxxxxxxxx>
  • To: <jawsscripts@xxxxxxxxxxxxx>
  • Date: Mon, 9 May 2016 11:58:22 +1000

Hi Kaveinthran,

GetTickCount is the function I was referring to.

TickCount is only what I called the value returned by GetTickCount.

Brief explanation of the function GetTickCount:

Windows adds 1 to an internal integer each 1 thousandth of a second.  That 
internal integer is 0 when Windows starts.  That process continues while 
Windows is running.  

JAWS uses GetTickCount to obtain the number in that Windows internal integer.  
If you divide the value returned by that function by 1000, that will be the 
number of seconds from when Windows started.


Below is a script to test or explain the function.  I suggest you run it, then 
add lines, re arrange them, and generally play with it to gain an understanding.

Globals
Int GlobalTicksAtStart


Script TestTickCounter ()
var
INT  CurrentTickCount

let CurrentTickCount = GetTickCount ()

SayInteger (CurrentTickCount - GlobalTicksAtStart)  SayString ("milliseconds.  
")

SayInteger ((CurrentTickCount - GlobalTicksAtStart) / 1000)    SayString (" 
seconds ")

let GlobalTicksAtStart = CurrentTickCount

EndScript

The first time you run it, it will say the count from Windows startup, then the 
number of seconds from startup.

On following runs, the announcements will be from the last time you ran it.

Regards,
Paul from Australia.

-----Original Message-----
From: jawsscripts-bounce@xxxxxxxxxxxxx 
[mailto:jawsscripts-bounce@xxxxxxxxxxxxx] On Behalf Of Kaveinthran Pulanthran

hi paul,

thanks very much, I amd catching up, but I am not good in messing with the 
tickcount, can you exlain on the use of tickcount, and how it applies on timer,

I had use gettickcount/1000 but I am getting 5 dijit numbers, how to use these 
5 digits wisely?

thanks

On 5/8/16, Paul Magill <magills@xxxxxxxxxxx> wrote:

Hi,

The first part is relatively straightforward.

1. Create 2 global integer variables.  One to store 1 or 0, true or 
false to whether the timer has been started, and the second to store 
the count from GetTickCount.
For the below explanation, I'll call the first one, 
GlobalTimerStarted, and the second one, GlobalTicksAtStart.

2. In the script, the code would look something like this. Note, this 
is not JAWS scripting code, just pseudo code:

If GlobalTimerStarted = 0 (it will be 0 on start up) 
GlobalTicksAtStart = GetTickCount () GlobalTimerStarted = 1 Say 
message to tell user the timer has started ELSE  the variable 
GlobalTimerStarted would be 1 Subtract GlobalTicksAtStart from value 
returned from GetTickCount () Do calculations to obtain hours, minutes 
seconds Say the result Set GlobalTimerStarted back to 0, or you will 
not be able to restart it.
End if

The second part will require a lot more work.

One approach would be:

1. create a script to obtain the time period, calculate what the tick 
count would be for that period, and store that in a global. Also store 
in a global the current TickCount.
   That script could also be used to check the progress Schedule a 
function to periodically check whether the current tickCount has 
reached the starting Tickcount plus the periods TickCount.

2. create the  function to periodically check, , via ScheduleFunction, 
whether the current TickCount has reached the future time,  also, the 
10 second notice, and playing the sound when done.

4 global integers would be required. For the explanation, I'll call 
them, GlobalTimerStarted, GlobalTicksAtStart, GlobalPeriodAsTicks, and 
Global10SecondNoticeSaid.

Code would look something like this:

Script xxxx
If GlobalTimerStarted == 0
Get the time period required using the function InputBox (......) 
Separate the hours, minutes and seconds, convert them to integers, and 
do the calculations to obtain the time period in milliseconds, as used 
by GetTickCount.  Store this in GlobalPeriodAsTicks.
Let GlobalTicksAtStart = GetTickCount () Let Global10SecondNoticeSaid 
= 0 (false) Use ScheduleFunction to call the checking function.
ELSE  the variable GlobalTimerStarted would be 1, so you are 
announcing the progress Get the current TickCount For the time 
elapsed, subtract GlobalTicksAtStart from the current TickCount.
For the time remaining, subtract the current TickCount from the total 
of GlobalTicksAtStart + GlobalPeriodAsTicks Do the calculations to 
obtain these in minutes seconds etc Announce the result End if

Function YYY
Note, this has been called via  ScheduleFunction Get the current 
TickCount If currentTickCount > (GlobalTimerStarted + 
GlobalPeriodAsTicks) ; the period has been reached Play sound, and any 
message required Set GlobalTimerStarted back to 0, or you will not be 
able to restart it.
RETURN  ; you don’t want to re schedule this function ELIF  
(currentTickCount  + 10000) > (GlobalTicksAtStart +
GlobalPeriodAsTicks)   ; now within 10 seconds of the period end
If Global10SecondNoticeSaid = 0
Say the 10 second notice
Let Global10SecondNoticeSaid = 1  ; so it wont continue to be said End 
if notice said End if time reached ScheduleFunction this function End 
function

End code outline.

Depending on how accurate you want the time checking, as to how long 
you use for the scheduleFunction.  Remember that ScheduleFunction uses 
tenths of a second, where GetTickCount uses thousands of a second.

The conversion of normal time periods such as minutes and seconds to 
milliseconds, and the reverse, can be tedious, so I suggest you create 
separate functions to do these.

** I have not provided a way to interrupt this process once started, 
so you may wish to either have a second keystroke / script to set 
GlobalPeriodAsTicks to 0, or in the existing script, use IsSameScript 
to do that.

That would cause the checking function to assess that the period had 
elapsed.

Hope this helps,
Paul from Australia

-----Original Message-----
From: jawsscripts-bounce@xxxxxxxxxxxxx 
[mailto:jawsscripts-bounce@xxxxxxxxxxxxx] On Behalf Of Kaveinthran ;
Pulanthran
Sent: Sunday, 8 May 2016 1:07 PM
To: jawsscripts@xxxxxxxxxxxxx
Subject: [jawsscripts] Re: simple timer/countdown script

hi,

thanks for that explanation,
I am having an idea to operate the script like this

1. user press a key and timer started
2. press the same key again, timer stoppes and it will announce the 
length of time, for examples 3.4 seconds

for countdown:
1. user press a key, and jaws will prompt for value of hour, seconds, 
or minutes 2. let's say user enter 2 minutes and pres enter, jaws will 
stat counting, 3. user can press key to know the time elapse and 
remaining, and jaws will remind before 10 or  15 seconds the countdown 
will end 4. after it finishes, jaws will play a sound,

this is my rough plan,

thanks

On 5/8/16, Paul Magill <magills@xxxxxxxxxxx> wrote:
Hi,

I'm sure there will be other ways, but you may wish to consider using 
the function, ScheduleFunction:

1. In a script, store in a global string, the time that is required.
This would need to be in the same format as that provided by function 
SysGetTime.
Then, in the same script, ScheduleFunction the function in point 2.

2. create a function that gets the current time from SysGetTime, and 
compares it to that stored in the global string with the appropriate 
display/response if it matches.  When the match fails, the ELSE 
statement, re ScheduleFunttion the same function.

3. The important bits.    The function will need to be in the default
file,
so it continues to call itself even when you alt-tab around. This 
recalling is fairly reliable, but can fail for reasons I didn't discover.

If it does fail, then you can add to the function in step 2, a step 
to place the current GetTickCount in a Global Integer variable.
Then in AutoStartEvent, check if the current GetTickCount differs 
from that in the Global Integer by no more than the Tick count  that 
would elapse between the ScheduleFunction calls, and if it does, call 
the function in step 2.

Note, I used this method years ago when I was testing 
ScheduleFunction for another purpose.

Hope this helps.

Regards,
Paul from Australia.

-----Original Message-----
From: jawsscripts-bounce@xxxxxxxxxxxxx 
[mailto:jawsscripts-bounce@xxxxxxxxxxxxx] On Behalf Of Kaveinthran ;
Pulanthran hi friends,

I am planning to write a personal timer/countdown script,  but no 
idea where to start. Can someone throw ideas on this?

thanks
__________

__________

View the list's information and change your settings at 
http://www.freelists.org/list/jawsscripts


__________

View the list's information and change your settings at 
http://www.freelists.org/list/jawsscripts

__________ 

View the list's information and change your settings at 
http://www.freelists.org/list/jawsscripts


__________ 

View the list's information and change your settings at 
http://www.freelists.org/list/jawsscripts

__________�

View the list's information and change your settings at 
http://www.freelists.org/list/jawsscripts

Other related posts: