LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices



Reply
 
Search this Thread
Old 04-25-2007, 04:30 PM   #1
dezireduser
Member
 
Registered: Nov 2005
Posts: 38

Rep: Reputation: 15
Question Lap Timer Software or Script NEEDED!


Hello everyone,

I'm sorry if this sounds like a stupid question but I've tried searching and haven't been able to find a suitable answer.

Is there a timer software with an unlimited lap feature for linux or as a java applet?
Something like this lap timer.

If not, then what's the quickest way to make a simple script that will record the time whenever a key is pressed.

What I basically want to do is start a timer and then whenever I press the space bar, have:
1. the time elapsed since the last press
2. the time elapsed since the timer was started

recorded into a text file. I want to have this repeated an unlimited number of times.

So, the generated text file should look something like this:

#HH:MM:SS.sss = hours:minutes:seconds.seconds
#ELAPSED----------LAP

00:00:00.000----------00:00:00.000
00:00:00.675----------00:00:00.675
00:00:01.775----------00:00:01.100
00:00:34.000----------00:00:32.225
00:00:37.500----------00:00:03.500
00:21:11.000----------00:20:33.500
00:21:12.000----------00:00:01.000
00:59:59.000----------00:38:47.000
02:00:00.123----------01:00:01.123
02:00:01.453----------00:00:01.453
.
.
.


The way I'm doing this currently is binding an alias to the date command and having the output appended to a text file and then processing and formatting that data. Something that automatically does all this in one step would be great.

Thanks for any help and any pointers!

D

Last edited by dezireduser; 04-25-2007 at 04:48 PM.
 
Old 04-25-2007, 08:18 PM   #2
drawde83
Member
 
Registered: May 2006
Location: New Zealand
Distribution: ubuntu, gentoo at uni
Posts: 30

Rep: Reputation: 15
would something written in java be suitable I think I could code something up fairly easily.
 
Old 04-26-2007, 06:03 AM   #3
drawde83
Member
 
Registered: May 2006
Location: New Zealand
Distribution: ubuntu, gentoo at uni
Posts: 30

Rep: Reputation: 15
This should do the trick, it'll tell you what to do when you run it. If you want to save the results just redirect it to a file.

Code:
import java.lang.Exception;
import java.text.SimpleDateFormat;
import java.util.Date;

public class LapTimer {

	public static void main(String[] arg){
		long glStart;
		long lapStart;
		char ch = ' ';
		SimpleDateFormat formatter = new SimpleDateFormat("KK:mm:ss:SSS");
		glStart = System.currentTimeMillis();
		lapStart = 0;

		System.out.println("# format is: Hours:Minutes:Seconds:Milliseconds");
		System.out.println("# Elapsed time, Lap Time");
		System.out.println("# press enter to end the current lap");
		System.out.println("# type 'q' and enter to quit");

		do{
			long elapsed,lapTime;

			if(ch != ' '){
				elapsed = System.currentTimeMillis() - glStart;

				if(lapStart == 0){ // if on first lap
					lapTime = elapsed;
				} else {
					lapTime = elapsed - lapStart;
				}
			
				System.out.print(formatter.format(new Date(elapsed)) + "," + formatter.format(new Date(lapTime)));
			
				lapStart = elapsed;
			}
			//ask for new control character

			try{
				ch = (char) System.in.read();
			}catch(Exception ex){
				System.out.println("Oh No!!!!");
			}

		}while(ch != 'q');
		
	}
 
Old 04-26-2007, 06:12 AM   #4
drawde83
Member
 
Registered: May 2006
Location: New Zealand
Distribution: ubuntu, gentoo at uni
Posts: 30

Rep: Reputation: 15
actually I just tried redirecting it and it doesn't work too well.
 
  


Reply

Tags
code, script, timer


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
timer in a shell script sanjith11 Programming 8 04-15-2011 11:32 PM
Multimedia timer (SMP friendly timer) bigqueso Linux - Kernel 0 03-15-2007 04:49 PM
Timer software for Cybercafe running on Red Hat jibade Linux - Software 1 10-04-2004 12:42 AM
speed up the slack in my lap Goatdemon Slackware 42 02-22-2004 03:34 AM
Bitchix timer script zeky Linux - Software 0 11-16-2002 11:24 AM


All times are GMT -5. The time now is 11:33 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration