linux keypress events

hi ,
Is there any way to keep track of keypress events in linux console program ???
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.
Topic archived. No new replies allowed.