以下程序是结合我的驱动编写的应用层程序,双击,单击,长按都能正确识别,效果很好,不知有哪位大侠有更好的结构和算法程序?想借此抛砖引玉,也愿高手们修改指正!QQ:26451602. /* 读取键值,控制LED灯亮。0x80-0x85:灭1-6号灯。0x00-0x05:点亮1-6号灯。 键值:1-6. 修改记录: 2009-10-26: 依据阿潘要求,改为刚按下/按住/释放都要给应用层信号。 修改标志:ZMF091026 */ #include <unistd.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <sys/ioctl.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <sys/select.h> #include <sys/time.h> #include <errno.h> #include <signal.h> #include <pthread.h> #include "sysconfig.h" #include "powercontrolboard.h" /* keyflag: bit4:y/n longkey; bit0:y/n quickkey; bit1:quickkey valid; bit5: key valid; */ /* keyflag: bit8-bit11: pressed key num:1-15 */ #define QUICKKEYbit 0 #define QUICKKEYVALbit 1 #define LONGKEYbit 4 #define KEYVALIDbit 5 volatile key_reg_t keyregdat; pthread_t g_LedCheckThreadId; int ledrpm_key_reg(int keyfd){ volatile int ret, key_val,keyflag=keyregdat.key_flag; ret=read(keyfd, (char *)&key_val,sizeof(key_val)); if (ret<0){ perror("ledrpm_key_reg:read"); goto ERRRT; } if(ret==0) return 0;/* 非阻塞读键盘返回0*/ printf("button%x/n",key_val); if(key_val < 0x1000){ /* 初始值处理 */ if(key_val==keyregdat.keybuf[0]){ SETBIT(keyflag, QUICKKEYVALbit); }else{ CLRBIT(keyflag, QUICKKEYVALbit); keyregdat.press_holdtime=0; keyregdat.keybuf[1]=keyregdat.keybuf[2]=0; keyregdat.keybuf[0