LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   Some system calls (http://www.linuxquestions.org/questions/programming-9/some-system-calls-256983/)

Spooky 11-19-2004 05: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 11:17 AM

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

#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);
      assert(res==0);
          //---- 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);
      c=getchar();
          //------  restore old settings ---------
      res=tcsetattr(STDIN_FILENO, TCSANOW, &org_opts);
      assert(res==0);
      return(c);
}



All times are GMT -5. The time now is 01:44 PM.