[Are] lines 7-13 needed ... ? |
Yes, you need the function in order to use it.
Also, the iskeypressed() restricts the time. |
That is right. The function only returns after the given number of milliseconds have passed (hence, it is a timeout). If you want to forcibly wait only until a key is pressed, then use
iskeypressed( INFINITE )
. If you only want to check to see if a key is pressed (or rather, waiting to be read)
right now, then the timeout should be zero (the default).
However, you usually want to be able to moderate the speed of your loop, like the example I gave you does, so you can specify how many ms to wait per iteration.
Does it really work for breaking the loop? |
Did the example code not work? (Answer: yes, of course it works. You might want to try actually compiling and running the example I gave you so you better understand what it does and how it works.)
And also how can I fix the iskeypressed() to be responded only by pressing ENTER? |
You cannot. You first need to know that a key is waiting to be read. Once it is, read the key. If the key is the
Enter key, then break the loop. Otherwise continue as if nothing had happened.
To read a single key on Windows, see:
http://www.cplusplus.com/forum/beginner/3523/#msg15435
Keep in mind that this is a pretty simple function, and may not work properly for
any key the user presses...
Good luck!