九鼎创展论坛中文版English
登录 | 立即注册 设为首页收藏本站 切换到宽版
查看: 3686|回复: 0
打印 上一主题 下一主题

基于x210ii/i210开发板linux+qt平台的按键测试程序

[复制链接]
跳转到指定楼层
楼主
发表于 2012-9-22 12:31:33 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
/***************************************************************/
// 编制:lqm
// 日期:2012-9-22
// 平台:x210/x210ii/i210开发板
// 测试方法:执行如下指令编译源码:
// arm-none-linux-gnueabi-gcc -o button button.c
// 将生成的button可执行文件拷贝到开发板并运行:
// ./button
// 按开发板上的六个按键,会有不同的键值消息打印出来.
/***************************************************************/

#include <stdio.h>  
#include <sys/types.h>  
#include <sys/stat.h>  
#include <fcntl.h>  
#include <linux/input.h>

int main()  
{  
    int keys_fd;                     //按键句柄   
    char ret[2];   s
    struct input_event t;  

    keys_fd = open("/dev/event0", O_RDONLY);  
    if(keys_fd<=0)  
    {  
        printf("open /dev/event0 device error!\n");  
        return 0;  
    }

    while(1)  
    {     
        if(read(keys_fd,&t,sizeof(t))==sizeof(t))
        {  
            if(t.type==EV_KEY)          //获取的是按键消息  
                    if(t.value==0 || t.value==1)    //返回值是1或者0  
                printf("key %d %s\n",t.code,(t.value)?"Pressed":"Released");     //1表按下,0表弹起  
        }
    }
    close(keys_fd);

    return 0;
}


回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|手机版|小黑屋|深圳市九鼎创展科技官方论坛 ( 粤ICP备11028681号-2  

GMT+8, 2024-5-19 20:34 , Processed in 0.018474 second(s), 19 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表