To stop a timer by pressing an keystrokes

Hi can anyone teaching me about how write a C++ program to stop a timer to continue counting by just simply press ALT on keyboard to stop it
or just press s on keybord it will automatic start to counting without press s already then press enter the program just to start.
For other example if dont understand then i may give another example
when we enter a system ("pause"); it will come out with Press any key to continue. But at here I want just to press an ALT key to stop the timer continue to counting.
I am using DEV. Thx for the one who reply first.
You may e-mail to me juliustan88@hotmail.com
Last edited on
(If you're hoping for code: sorry, we don't give code away. http://www.cplusplus.com/forum/articles/1295/)

You will need the time.h library for the timer: http://www.cplusplus.com/reference/clibrary/ctime/

To check for input without waithing, you can use getch() from conio.h. You can use a typecast to integer, to make it easy to compare. Search in this forum if you need more information.

Hope this helps. Good luck.
I am not hoping for code I want to get the ideal which field I should go in to fine.
the timer i know how to do.
but how to stop it by just press Alt 1 time in keybord without pressing enter.
And becasue in the ASCII there are no any code for ALF SHIFT CTRL ect
so how we can make it to get the signal when user press the keybord and it can react immediately.(press ALT then the timer will stop to count)
Some ways of getting keyboard input were discussed here: http://www.cplusplus.com/forum/windows/6476/
thx for the link it is very usefull
but at here i got another question to ask
if GetAsyncKeyState(VK_code) is to get any key you want into buffer
then got any ideal to clear/flush the buffer for that type of input???
else the keypress signal will always be there and i want the user to press that key again will fail casue it like keep on looping the same thing.
You dont need to clear/flush the buffer for that (it's possible, but I think things get more complicated):

1
2
3
4
5
6
7
8
9
bool firstPress=true;
if (firstPress)
{
    if (getAsyncKeySate())
    {
    //do stuff
    firstPress=false;
    }
}
Topic archived. No new replies allowed.