does anyone know how to implement "to continue press any key" in C on dos
I just need to know how to know when any key is being pressed on the keyboard.
Also i would like to know how to tell which key is being pressed if anyone knows.
Thanks
Printable View
does anyone know how to implement "to continue press any key" in C on dos
I just need to know how to know when any key is being pressed on the keyboard.
Also i would like to know how to tell which key is being pressed if anyone knows.
Thanks
Try the getch(); for just one key press or getchar(); for more then 1 key press.
if you dont want the program to stop and wait for the key press use the kbhit(); and then later use getch(); or getchar(); to read what key(s) they pressed.
thanks for the reply but with getch() and getchar() the user has to press return before the program moves on. i want the program to move on immediately after any key is pressed on the keyboard
any hints
You could make a loop that loops until the user presses a key using the kbhit() for breaking
Code:
#include <conio.h>
while(kbhit() == 0)
{
DoCoolThings();
}
that worked well but now the character of the key the user presses shows up at the next command prompt. how do i get rid of this character so that it doesnt show up anywhere
you could use clrscr(); after using the kbhit() loop
Hi,
Try this.
#include <conio.h>
#include <stdio.h>
int main()
{
char a;
while(!kbhit())
{
//do whatever
}
getch();// captures the char from kbhit
return 0;
}
use
#include <iostream.h>
#include <stdlib.h> /* needed for system() */
int main()
{
system("pause");
return 0;
}
Output:
Preass any key to continue...
Bam! :D