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

📄 keytest.c

📁 Linux s3c2410键盘驱动源码
💻 C
字号:
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <sys/time.h>
#include <sys/types.h>
#include <unistd.h>

main()
{
   fd_set rfds;
   struct timeval tv;
   int retval;

   int fileno;
   int ts, maxfd;
   int  ret= 0;
   char val=0;

    fileno = open("/dev/key",O_RDONLY);
    if (fileno == -1) {
        printf("open device key error!\n");
        return 0;
    }
    printf("press '*' to exit\n");
    while(1)
    {
        FD_ZERO(&rfds);
        FD_SET(fileno, &rfds);
        /* Wait up to five seconds. */
        tv.tv_sec = 5;
        tv.tv_usec = 0;

        maxfd =  fileno;
        retval = select(maxfd+1, &rfds, NULL, NULL, &tv);
        /* Don't rely on the value of tv now! */
        if (retval)
        {
             if (FD_ISSET(fileno, &rfds))
             {
                 if (read(fileno, &val, 1) == 0)
                 {
                     if(val=='*'){
		        	printf("\n");	
			        goto exit;
		     }else       printf("Key %c pressed\n",val);
                 }
     	     }else   printf("read error\n");
        }

    }
exit:
        close(fileno);
        close(ts);
        return 0;

}

⌨️ 快捷键说明

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