Key Presses

How would one wait for a key press let's say "P" to do something in the program but the program mustn't ask for it. So you can do it whenever but the program doesn't wait for you to press it it just carries on with its code.
So I don't want it to ask for an input.
Is this even possible.
Thanks
yes its possible , this is what you see in video games. The enemies keep killing you
until you press a "KEY" to hit and distroy them.

This can also be seen in many creative coding frameworks where the draw function keeps on running infinitely and to make some changes you have assigned a key to the drawn part and a separate key to close the program


A simple pseudocode :

1
2
3
4
5
6
char ch;
while ((cin>ch) != 'u'){

//do whatever you want 

}


the above code might be a little vague , but if you really want to see a live system
download some creative coding or gamedev framework like "open frameworks " and run the examples or create something of your own from it , they have a special function like :

Openframework has this ->

1
2
3
4
5
6
7
8
9
10
11
12
13
14

void testApp::keyPressed(int key){

// specify keys and their action
//for eg.


  if(key == 'r'){ 
// do something like move increase size , decrease size , produce sound and whatnot
 }



}
Topic archived. No new replies allowed.