IF KeyDown Problem.

Hello everyone!

I'm new at C++ but have been programming in other languages too, so i'm not a total beginner.

I want to make simple games in the command prompt. But i need an IF statement to check if an arrow key is hold down.
I don't want an event. Cus last time i got this output:
1
2
3
4
5
6
7
Running...
Key is down...
Running...
Running...
Key is down...
Key is down...
Key is down...

If you open up Word or another texteditor, try to hold down the K key, and you will find out that it starts typing K one time, then after some miliseconds it will start "spamming" with the K key.
The same happened in my game. And i don't want that delay between the 1st K and the next...

I already posted this question on another forum. But no1 could answer :( I hope you do! (:
- Anders4000
What library are you using? In Allegro, there's a global array called key, which can be used like
if(key[KEY_DOWN])blah();
Well... I got no libs :p I tried to download and install them. But i am 14 years old, and it is just too hard for me (:

So i thought, What about making Space Invaders just using standard C++ in a command prompt?

...I use Codeblocks/Bloodshed, but don't think that makes any difference.
Do i need a lib for KeyDown in an if statement?

Or can i actually find a event which will give me output without the delay?
- Anders4000
You need a game library. Programming games in the console is hell. Try the Allegro game library, it's the one that I use. There's also wxwidgets, or openGL if you're looking for 3d.
Only problem is that i get so damn confused installing and downloading such. Installing is very complicated, and i've tried with 2-3 libs and it never worked. What program you use for the coding? Code::Blocks?
try this go to step 2 here:
http://wiki.allegro.cc/index.php?title=Code::Blocks
I use linux, so I would suggest asking in the windows porgramming forum on setup and so on. Once you have allegro, it's really easy to make simple games.
Last edited on
Found a vid showing it on youtube (: Thanks alot!

I should be able to find that KeyDown statement myself (:
- Anders4000
Topic archived. No new replies allowed.