Abhijeet Jha
Abhijeet Jha

Reputation: 51

How to detect when a specific key is pressed

I am currently working on my school project in Turbo C++. I am sorry but it is necessary for my code to work on Turbo C++. I plan on making a simple game, but with my beginner level knowledge, I cannot find a simple-to-understand method of detecting when and what arrow key is pressed.

In the game, I need to refresh my display regularly so I cannot use getch() to get the input as it will pause the game, but I don't know another way to get input without displaying it. So I thought to detect a key press and then use getch() but I don't know how to do that. Please help me figure out a simpler way to achieve this.

Upvotes: 0

Views: 409

Answers (1)

Abhijeet Jha
Abhijeet Jha

Reputation: 51

Sorry for disturbing anyone with this unnecessary post.

I have luckily stumbled upon kbhit() (which I didn't know existed) in conio.h works like a charm. It detects key presses without stopping or interrupting the main code.

Thanks,

Upvotes: 3

Related Questions