⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 1553_junk_bm-5_mykbhit.c

📁 BU-65550M2-605 PCMCIA card (1553) 的驱动程序源代码
💻 C
字号:

#include <stdio.h>
#include <string.h>
#include <termio.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <sys/time.h>
#include <sys/types.h>

struct termio current_io;
struct termio original_io;

//------------------------------------------------------------------------------

static void exit_handler(void) {

  fflush(stdin);
  if (ioctl(0, TCSETA, &original_io) == -1) {
    perror("ioctl(): TIOCSETP to reset original io");
  }
}

//------------------------------------------------------------------------------

int mykbhit() {

  fd_set rfds;
  struct timeval tv;
  static int first = 1;

  if (first) {
    first = 0;
    if (ioctl(0, TCGETA, &original_io) == -1) {
      perror("ioctl(): TIOCGETD");
      exit(1);
    }
    atexit(exit_handler);
    memcpy(&current_io, &original_io, sizeof(struct termio));
    current_io.c_cc[VMIN]  = 1;     // wait for one character
    current_io.c_cc[VTIME] = 0;     // and don't wait to return it
    current_io.c_lflag &= ~ICANON;  // unbuffered input
    current_io.c_lflag &= ~ECHO;    // turn off local display
    if (ioctl(0, TCSETA, &current_io) == -1) {
      perror("ioctl(): TIOCSETP");
      exit(1);
    }
  }

  FD_ZERO(&rfds);
  FD_SET(0, &rfds);
  tv.tv_sec  = 0;
  tv.tv_usec = 50;
  select(1, &rfds, NULL, NULL, &tv);
  if (FD_ISSET(0, &rfds)) return 1;
  else                    return 0;
}

//------------------------------------------------------------------------------
/*
int main(void) {

  int symbol;

  while (1) {
    if (mykbhit()) {
      symbol = fgetc(stdin);
      if (symbol == 0x1B || symbol == 0xE0) symbol = fgetc(stdin)<<8 | symbol;
      printf("You typed ascii %d   hex %X\r\n", symbol, symbol);
      if (symbol == 'q') break;
    }
  }
}
*/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -