Feb 27, 2009 at 6:42pm Feb 27, 2009 at 6:42pm UTC
hi ,
Is there any way to keep track of keypress events in linux console program ???
Mar 1, 2009 at 1:56pm Mar 1, 2009 at 1:56pm UTC
you just need to read from /dev/input/event0 using something like:
#define INPUT_QUEUE "/dev/input/event0"
#define EVENT_LEN 16
void readEventLine(FILE * in, char * data) { //read input key stream
int i;
for(i = 0; i <= 15; i++) { //each key press will trigger 16 characters of data, describing the event
data[i] = (char) fgetc(in);
}
}
int main() {
FILE * input;
char data[EVENT_LEN];
input = fopen(INPUT_QUEUE, "r+");
readEventLine(input, data);
}
Note though that the result will be in terms of the physical key codes (not ascii), so you'll have to map them to ascii...
Btw, sometimes for some reason you'll have to use event1 instead of 0.
Hope this helps.