新闻  |   论坛  |   博客  |   在线研讨会
按键处理
我就是我lxw | 2012-10-26 10:24:56    阅读:1627   发布文章

static INT8U step=0;
static INT8U RepeatCount;
static BOOLEAN AllPress;

switch (step)
{
 static INT8U PrevGetkey;
 case 0:
  if (Getkey)
  {
   PrevGetkey=Getkey;
   step=1;
   RepeatCount=0;
  }
  break;
 case 1:
  if (PrevGetkey==Getkey)
  {
   if (++RepeatCount > 8)//证明是长按
   {
    AllPress=1;
    RepeatCount = 0;
    printf("\r\n长按");
   }
   else//短按
   {
    printf("\r\n按下");
   }
  }
  else
  {
   step=2;
  }
  break;
 case 2:
 if (Getkey)
 {
  step=1;
 }
 else if (AllPress)//长按弹起不作处理。
 {
  AllPress=0;
  step=0;
  printf("\r\n长按弹起");
  break;
 }
 else//弹起
 {
  step=0;
  printf("\r\n弹起");
 }
  break;
}

*博客内容为网友个人发布,仅代表博主个人观点,如有侵权请联系工作人员删除。

参与讨论
登录后参与讨论
推荐文章
最近访客