button delay

This is a discussion on button delay within the C Programming forums, part of the General Programming Boards category; Hi, I cant work out how to wirte a program that counts the milliseconds befrore the same button is pressed ...

  1. #1
    Registered User
    Join Date
    Apr 2008
    Posts
    192

    button delay

    Hi,

    I cant work out how to wirte a program that counts the milliseconds befrore the same button is pressed twice, i.e if you press "3" then wait for a length of time then press "3" again, how long was the gap in milliseconds.

    anyone got any ideas?

    thanks
    alex

  2. #2
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,048
    There are two problems you have to solve here.

    First, you need to be able to get keypresses without having to hit enter. See this FAQ: http://faq.cprogramming.com/cgi-bin/...&id=1043284392
    Basically, with Dev-C++, you can use getche() if you include <ctype.h>. But be aware that this is an unportable function.

    Then you need to be able to record time. The easiest way to do this is to use clock() or time() from <time.h>. But those functions are rarely precise to the millisecond. For better (millisecond) precision, you again must use a non-standard function. I forget what the function is for Windows, try searching around.
    [edit] Maybe it was GetTickCount(). http://msdn2.microsoft.com/en-us/lib...08(VS.85).aspx [/edit]
    Last edited by dwks; 04-09-2008 at 12:56 PM.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 06-28-2008, 09:30 PM
  2. temperature sensors
    By danko in forum C Programming
    Replies: 22
    Last Post: 07-10-2007, 08:26 PM
  3. elliptical button
    By geek@02 in forum Windows Programming
    Replies: 0
    Last Post: 11-21-2006, 02:15 AM
  4. writing text over a deleted button
    By algi in forum Windows Programming
    Replies: 4
    Last Post: 05-02-2005, 12:32 PM
  5. Window won't display on button command!?
    By psychopath in forum Windows Programming
    Replies: 6
    Last Post: 06-22-2004, 09:12 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21