设置一个bool变量为true
Settimer(500)
在ontimer中设置bool为false键盘消息在bool=true的时候接受.

解决方案 »

  1.   

    #include <sys/time.h>
    #include <sys/types.h>
    #include <unistd.h>
    int  select(int  n,  fd_set  *readfds,  fd_set  *writefds,
           fd_set *exceptfds, struct timeval *timeout);timeout.tv_sec=0  //
    timeout.tv_usec=5000; //example:
        
           main(void) {
               fd_set rfds;
               struct timeval tv;
               int retval;           /* Watch stdin (fd 0) to see when it has input. */
               FD_ZERO(&rfds);
               FD_SET(0, &rfds);
               /* Wait up to five seconds. */
               tv.tv_sec = 5;
               tv.tv_usec = 0;           retval = select(fileno(stdin), &rfds, NULL, NULL, &tv);
               /* Don't rely on the value of tv now! */           if (retval) {
                   printf("Data is available now.\n");
                   /* FD_ISSET(0, &rfds) will be true. */
                   int c=fgetc(stdin);
               }
               else
                   printf("No data within half seconds.\n");           exit(0);
           }
      

  2.   

    sorry , i make mistake            tv.tv_sec = 5;
               tv.tv_usec = 0;should be :timeout.tv_sec=0  //
    timeout.tv_usec=5000; //