Reputation: 11
My name is Andrea. I'm using Turbo C++ on an old PII 350 MHz with dos 7. I've written a while cycle which does something. I have to check a which letter of the keyboard has been pressed without checking it in the cycle in order to avoid it to slow down. Is there a way to set an interrupt like in arduino to stop the cycle only when a key is pressed? I've tried with bioskey(0) in the cycle but it slows it down too much....
Upvotes: 1
Views: 173
Reputation: 543
You can use the getch()
function in <conio.h>
, which pauses program execution until one key is pressed, and returns the character of the pressed key.
Example:
#include <stdio.h>
#include <conio.h>
int main()
{
puts("Hello World, press any key to continue.");
getch();
puts("Finished");
return 0;
}
Note that <conio.h>
is a non-standard library. The <conio.h>
library and the function are also available in modern versions of Visual C++, but the function is called _getch()
.
Upvotes: 0