> I am not sure how you would do it in C++.
But, you could write
> an assembly routine(or a function in
assembly language using the
> 'asm' keyword) to trap a keypress. I think,
the interrupt you
> need to use is INT 09 (Intel
platform-specific).
Have you tried this under Linux? I havn't, so
this might be wrong, but as far as I know you
need priviledge level 0 to trap a hardware
interrupt, while a normal process runs with
priviledge level 3. The iopl() system call
can be used to change this, but it's not
exactly friendly.
> Anyone has a better solution ?
Try putting the terminal into raw mode:
int handle;
char buffer[128];
handle = open("/dev/tty", O_RDWR);
ioctl(handle, KDSKBMODE, K_RAW);
//This read returns as soon as a key is
pressed or released.
//Use gettimeofday() to find timings exact
timings.
//Unfortunately, I'm not sure how to get
character codes from
//this buffer. Get the source to showkey to
find this.
read(handle, buffer, 128);
close(handle);
Make sure you allow some way of quitting if
you do this - putting the keyboard into raw
mode disables console switching, Ctrl-C, etc.
Steven.
-
To unsubscribe from this list: send the line "unsubscribe linux-newbie" in
the body of a message to [EMAIL PROTECTED]
Please read the FAQ at http://www.linux-learn.org/faqs