-   Programming (
-   -   Some system calls (

Spooky 11-19-2004 04:10 PM

Some system calls
hi there!

I need to make a C function that reads from stdin using ioctl() read() gettimeofday() system call's to when some char apears on the screen it get's the exact time that i took to press the right key...
how can i do this?

jim mcnamara 11-24-2004 10:17 AM

Here is a start on your homework, this reads a single keypress:

#include <termios.h>
#include <unistd.h>
#include <assert.h>
#include <string.h>
int getch(void) {
      int c=0;

      struct termios org_opts, new_opts;
      int res=0;
          //-----  store old settings -----------
      res=tcgetattr(STDIN_FILENO, &org_opts);
          //---- set new terminal parms --------
      memcpy(&new_opts, &org_opts, sizeof(new_opts));
      new_opts.c_lflag &= ~(ICANON | ECHO | ECHOE | ECHOK | ECHONL | ECHOPRT | ECHOKE | ICRNL);
      tcsetattr(STDIN_FILENO, TCSANOW, &new_opts);
          //------  restore old settings ---------
      res=tcsetattr(STDIN_FILENO, TCSANOW, &org_opts);

All times are GMT -5. The time now is 12:00 AM.