Thread: button delay

  1. #1
    Registered User
    Join Date
    Apr 2008

    button delay


    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?


  2. #2
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    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:
    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(). [/edit]
    Last edited by dwks; 04-09-2008 at 11:56 AM.

    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:

    My website:
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 06-28-2008, 08:30 PM
  2. temperature sensors
    By danko in forum C Programming
    Replies: 22
    Last Post: 07-10-2007, 07: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, 11:32 AM
  5. Window won't display on button command!?
    By psychopath in forum Windows Programming
    Replies: 6
    Last Post: 06-22-2004, 08:12 PM