zoukankan      html  css  js  c++  java
  • _kbhit() for linux

    传送门:http://cboard.cprogramming.com/c-programming/63166-kbhit-linux.html

    #include <stdio.h>
    #include <unistd.h>
    #include <stdlib.h>
    #include <termios.h>
    #include <unistd.h>
    #include <fcntl.h>
     
    int kbhit(void)
    {
      struct termios oldt, newt;
      int ch;
      int oldf;
     
      tcgetattr(STDIN_FILENO, &oldt);
      newt = oldt;
      newt.c_lflag &= ~(ICANON | ECHO);
      tcsetattr(STDIN_FILENO, TCSANOW, &newt);
      oldf = fcntl(STDIN_FILENO, F_GETFL, 0);
      fcntl(STDIN_FILENO, F_SETFL, oldf | O_NONBLOCK);
     
      ch = getchar();
     
      tcsetattr(STDIN_FILENO, TCSANOW, &oldt);
      fcntl(STDIN_FILENO, F_SETFL, oldf);
     
      if(ch != EOF)
      {
        ungetc(ch, stdin);
        return 1;
      }
     
      return 0;
    }
     
     
    main( int argc, char** argv )
    {
        char *input = argv[0];
        int nomor = argc;
        pid_t pid = 0;
        /* set stuff up */
        /* accept command line args */
         
        pid = fork();
        if( pid == 0 ){
            /* this is the "background" process.  Execute process loop here */
            int x=0;    
            while(1)
            {
                if(kbhit())
                  printf("you hit keyboard");
            }
        }
        else {
            /* "foreground" process exits */
            exit(0);
        }
    }

    具体含义,有的解释是等待键盘输入;但此处用意为在 ios下使用while( !kbhit()) 控制openal的音效的循环播放.

  • 相关阅读:
    在VMWare的虚拟机中设置共享文件夹(Linux-Ubuntu系统)
    得到cell视图
    推送
    常用框架
    截屏
    多线程枷锁
    java与IOS的交互
    缓存机制
    iOS数据库操作(使用FMDB)
    插入排序
  • 原文地址:https://www.cnblogs.com/wainiwann/p/3558295.html
Copyright © 2011-2022 走看看