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

📄 testkey.c

📁 4x4按键的嵌入式Linux驱动 平台:AT91RM92
💻 C
字号:
/*****************************************************************************
;Copyright (C) 2005  Hyesco Technology Co.,Ltd
;Institue of Automation, Chinese Academy of Sciences
;
;WebSite:				www.hyesco.com
;Description: 	Keyboard test on Linux 
;Date:					2006-11-15		
;Author:				Hyesco			
;E_mail:				Lijg@hyesco.com
*****************************************************************************/

#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <sys/time.h>
#include <sys/types.h>
#include <unistd.h>

int main(int argc,char **argv)
{
		fd_set rfds;
   	int retval;
   	int fd;
   	
   	unsigned char number=0; 
   	struct timeval tv;
   
   	fd = open("/dev/key",O_RDONLY);
   	if (fd <0) 
   		{
   		printf("open device key error!\n");
      return 0;
    	}
    
		tv.tv_sec=1;
		tv.tv_usec=0;

		while(1)
			{
			FD_ZERO(&rfds);
			FD_SET(fd,&rfds);
			if (select(1+fd,&rfds,NULL,NULL,&tv)>0)
				{
				if(FD_ISSET(fd,&rfds))
					{	
					retval=read(fd, &number, 1);
					if (retval> 0)
						printf("key %x stroke\n", number);
					}
				}
		}

   	close(fd);
    return 0;
}

⌨️ 快捷键说明

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