提起按键程序,我坚决支持所长的,你若将所长的程序读懂,我读了他的程序按照他的框架写了一个,感觉挺好用。
// if( ( sKeyProce.KeyVal != 0x1f ) || ( sKeyProce.KeyVal != sKeyProce.KeyLastTime ) ){ //有键按下,处理
keycompare1 = sKeyProce.KeyLastTime & sKeyProce.KeyProcBit; //上次按键位的按键状态
keycompare2 = sKeyProce.KeyVal & sKeyProce.KeyProcBit; //当前按键位的按键状态
switch ( sKeyProce.keyTask ){
case Idle: switch ( KeyState() ){
case keypushmove: sKeyProce.keyTask = pushdelay; //按键按下,转入按键延时判断
break;
case keypopmove: sKeyProce.keyTask = popdelay;
break;
case keynomove: sKeyProce.keyTask = Idle; //按键无动作,转入空闲状态
break;
default: break;
}
break;
case pushdelay: //if( ( sKeyProce.KeyLastTime & sKeyProce.KeyProcBit ) == ( sKeyProce.KeyVal & sKeyProce.KeyProcBit ) ){
if( keycompare1 == keycompare2 ){ //两次状态相同,按键有效
sKeyProce.keyTask = pushcheck;
}else{
sKeyProce.keyTask = Idle; //否则,为抖动,推出按键处理
}
break;
case popdelay: //if( ( sKeyProce.KeyLastTime & sKeyProce.KeyProcBit ) == ( sKeyProce.KeyVal & sKeyProce.KeyProcBit ) ){
if( keycompare1 == keycompare2 ){
sKeyProce.keyTask = popcheck;
}else{
sKeyProce.keyTask = Idle;
}
break;
case pushcheck: //if( ( sKeyProce.KeyLastTime & sKeyProce.KeyProcBit ) == ( sKeyProce.KeyVal & sKeyProce.KeyProcBit ) ){
if( keycompare1 == keycompare2 ){ //状态继续相同,按键有效,压入按键信息
PushMsg( sKeyProce.KeyProcBit ); //按键位
PushMsg( pushdown ); //按键状态
}
sKeyProce.keyTask = Idle; //一个完整的按键处理完毕,转入空闲状态
break;
case popcheck: //if( ( sKeyProce.KeyLastTime & sKeyProce.KeyProcBit ) == ( sKeyProce.KeyVal & sKeyProce.KeyProcBit ) ){
if( keycompare1 == keycompare2 ){
PushMsg( sKeyProce.KeyProcBit );
PushMsg( popup );
}
sKeyProce.keyTask = Idle;
break;
} |