#include #include enum state { ST_START, ST_ESCAPE, ST_CSI, ST_FNKEY, ST_FNKEY_END }; int main() { int c = 0; enum state st = ST_START; int fn_num = 0; while ((c = getchar()) != EOF) { if (c == '\x1b') st = ST_ESCAPE; else if (c == '[' && st == ST_ESCAPE) st = ST_CSI; else if (st == ST_CSI && isdigit(c)) { fn_num += 10 * (c - '0'); st = ST_FNKEY; } else if (st == ST_FNKEY && isdigit(c)) { fn_num += (c - '0'); printf("FN key pressed, number: %d\n", fn_num); st = ST_FNKEY_END; } else if (st == ST_FNKEY_END && c == '~') { st = ST_START; } else { printf("Saw character: %c\n", c); } } return 0; }