Skip to content

Instantly share code, notes, and snippets.

@KristianLyng
Created December 5, 2011 12:42
Show Gist options
  • Select an option

  • Save KristianLyng/1433478 to your computer and use it in GitHub Desktop.

Select an option

Save KristianLyng/1433478 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <stdlib.h>
#include <sys/time.h>
#include <sys/types.h>
#include <unistd.h>
#include <termios.h>
int
main(void)
{
struct termios t;
char foo[10];
char pre[] = {27,91,49};
char post[] = {126};
int i=0;
int f=0;
tcgetattr(0,&t);
t.c_lflag = t.c_lflag & ~(ICANON|ECHO);
tcsetattr(0,TCSANOW,&t);
while (1) {
read(0,foo,1);
if (i==5)
i=0;
if (i < 3 && pre[i] == foo[0]) {
i++;
} else if (i == 3) {
f = *foo - 48;
i++;
} else if (i == 4 && post[0] == foo[0]) {
i=5;
} else if (i>0) {
i=0;
f=0;
}
if(*foo == '.')
printf("period\n");
if(*foo == 27)
printf("esc\n");
if(f && i==5)
printf("f-key: %d\n",f);
printf("foo: %d\n",*foo);
}
exit(EXIT_SUCCESS);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment