Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2242022
  • 博文数量: 395
  • 博客积分: 10994
  • 博客等级: 上将
  • 技术积分: 5586
  • 用 户 组: 普通用户
  • 注册时间: 2010-12-17 19:49
文章存档

2014年(1)

2013年(10)

2012年(74)

2011年(303)

2010年(7)

分类: LINUX

2011-05-22 09:53:55

实例分析

//按键中断中报告事件

static void button-interrupt(int irq, void * dummy, struct pt-regs * fp)

{

    input_report_key(&button_dev, BTN_0inb(BUTTON_PORTO))

    input_report_key(& button_dev, BTN_1inb(BUTTON_PORTI))

    input_sync(&button_dev)

 

static int - -in it button-in it(void){

    //用户申请中断

    if (request-irq(BUTTON_IRQ, button_interrupt, 0, "button", NULL))

           return  -EBUSY

set_bit(EV_KEYbutton_dev.evbit)//支持EV_KEY事件

set_bit(BTN_0button_dev.keybit)//设备支持两个键

set_bit(BTN_1, button_dev.keybit)

input_register_device(&button_dev)//注册input设备

}

 

 

 

 

应用程序

struct input_event{

struct timeval time//按键时间

__ul6 type//类型,在下面有定义

__ul6 code//要模拟成什么按键

__s32 value//是接下还是释放

}

struct input_event ev_mouse[2I

fd = open {"devlinputlevent3".0_RDWR}

while(1){

    count=read(fdev__mousesizeof(struct input_event}}

    for{i=0i<(int}count/sizeof{struct input-event}i++}

    (

    if(EV_REL== ev_mouse[ i]. type){

              printf(time:%ld, %d”,ev_mouse.time.tv_secev_mouse.time.tv_usecl

printf(type:%d code:%d va[ue%dln",ev_mouse.typeev_mouse[i].codeev_mouse[i].va[ue}

if(EV_KEY== ev_mouse[i]. type ){

                   printf("time:%ld. %d"ev_mouse.time.tv_secev_mouse.time.tv_usec}

printfl(" type%d code0'sd vaLue%dtn"ev_mouse.typeev_mouser'1.codeev_mouser'].va}ue}

              }

       }

}

 

 

 

 

 

阅读(1104) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~