testkeyboard.c

来自「完整的S3C2410终端键盘驱动源程序」· C语言 代码 · 共 32 行

C
32
字号
/**************************start***********************/
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <sys/time.h>
#include <sys/types.h>
#include <unistd.h>
#include <asm/delay.h>

main()
{
	int fd;
	char key = 0;
	fd = open("/dev/button", O_RDWR);
	if (fd == -1)
	{
		printf("open device button errr!\n");
		return 0;
	}

	ioctl(fd, 0, 0);	//清空键盘缓冲区, 后面两个参数没有意义, 
	while(key != 16)
	{
		if (read(fd, &key, 1) > 0)
		{
			printf("*********************Key Value = %d*****************************\n", key);
		}
	}
	close(fd);
	return 0;
}

⌨️ 快捷键说明

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