Well if you're using glut, you can register a callback for that. Otherwise, you have to have a loop that continually check for it.
:DCode:#include <pthread.h>
pthread_t keyboard_thread;
void * keyboard(void * argument){
char mychar = '\0';
while(mychar != 'x'){ loop until an x is pressed
fflush(stdin);
scanf("%c",&mychar);
switch (mychar){
case ' ':
cout << "Space bar pressed" << endl;
break;
}
}
return 0;
}
int main(){
pthread_create(keyboard_thread, NULL, keyboard, NULL);
//Do whatever you want
return 0;
}
That's threading though, which is a little more complicated.