or if you need to more key options, you could always replace the if statement with a switch statement
if you want something that runs through the entire program( for example if anytime during the program, someone presses something something will happen, you need to learn about multithreading- check out sfml)
What you want is called "unbuffered input". I didn't think I had a simple example here, but a quick google search found me this one (Windows only): http://www.cplusplus.com/forum/beginner/9503/
You can do the same sort of thing on *nix systems too, but as I am not at home I'll leave that to you to google if you want it.
(Hmm, how about this: http://www.cplusplus.com/forum/beginner/5619/#msg25139 )
1) using my method this is not possible. duoas gave interesting info on unbuffered input. In my opinion, unbuffered input would be the best solution.
2) you could use allegro features. download the allegro library and use specific features made available through the library. im not too familiar with allegro but this would basically give what your looking for:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
#include <allegro.h>
usingnamespace std;
int main()
{
allegro_init();
install_keyboard();
if (key[KEY_F])
{
//do something
}
return 0;
}
END_OF_MAIN();
This basically does something if the f key is pressed (you dont need to press enter and the key can be pressed at any time). You could change the if statement with a switch if your looking for more keys. My advice to you is too still check out unbuffered input as Duoas suggested