I believe that the recommended approach would be to use ncurses as already mentioned by @CPlusPlus OOA and D.
Although you could implement a non-blocking "key-press-detector" with this code:
#include <iostream>
#include <stdio.h>
#include <conio.h>
#include <vector>
#include <termios.h>
#include <unistd.h>
#include <fcntl.h>
int kbhit(void) {
struct termios oldt, newt;
int ch;
int oldf;
tcgetattr(STDIN_FILENO, &oldt);
newt = oldt;
newt.c_lflag &= ~(ICANON | ECHO);
tcsetattr(STDIN_FILENO, TCSANOW, &newt);
oldf = fcntl(STDIN_FILENO, F_GETFL, 0);
fcntl(STDIN_FILENO, F_SETFL, oldf | O_NONBLOCK);
ch = getchar();
tcsetattr(STDIN_FILENO, TCSANOW, &oldt);
fcntl(STDIN_FILENO, F_SETFL, oldf);
if(ch != EOF) {
ungetc(ch, stdin);
return 1;
}
return 0;
}
char get_char(){
int k;
int i = 0;
while(i == 0){
if(kbhit()){
k = _getch();
i++;
}
}
return char(k);
}
int main() {
while(1) {
while(!kbhit()) {
// Works continuously until interrupted by keyboard input.
printf("Continuous...\n");
}
int c = get_char();
std::cout << c;
break; // Or whatever you want to do...
}
return 0;
}