Поскольку вы находитесь на Linux, вы можете использовать termios.h
, здесь эмуляция старого getch
(conio.h
):
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <termios.h>
#include <unistd.h>
static struct termios term, oterm;
static int getch(void)
{
int c = 0;
tcgetattr(0, &oterm);
memcpy(&term, &oterm, sizeof(term));
term.c_lflag &= ~(ICANON | ECHO);
term.c_cc[VMIN] = 1;
term.c_cc[VTIME] = 0;
tcsetattr(0, TCSANOW, &term);
c = getchar();
tcsetattr(0, TCSANOW, &oterm);
return c;
}
int main(void)
{
puts("Press Q to exit");
while (1) {
int c = getch();
switch (c)
{
case 'A':
case 'a':
puts("A was pressed");
break;
case 'D':
case 'd':
puts("D was pressed");
break;
/* ...*/
case 'Q':
case 'q':
exit(EXIT_SUCCESS);
default:
break;
}
}
return 0;
}