这个简单,你设置 8 个计数变量和 8 个标志变量就可以了。Dim intCount(7) As Integer, blnPushed(7) As Boolean另外,假定你可以通过一个 Get_Button_State 函数将 8 个按钮的当前状态写入变量 bytStatus。 Dim bytStatus As Byte比如你设置 Timer 的 Interval = 3 ms,在每次 Timer 事件时:bytStaus = Get_Button_State()For i = 0 To 7
If bytStaus And 1 Then '检查状态变量最低位所表示的按钮状态,如果是按下
If intCount(i) < 10 Then intCount(i) = intCount(i) + 1
If intCount(i) = 10 Then blnPushed(i) = True '连续按下 30 ms 或以上,确认状态
Else
intCount(i) = 0 '检测到放开状态,重新计数
blnPushed(i) = False
End If
BytStatus = BytStatus \ 2 '右移一位,以检查下一个按钮状态
Next i
If bytStaus And 1 Then '检查状态变量最低位所表示的按钮状态,如果是按下
If intCount(i) < 10 Then intCount(i) = intCount(i) + 1
If intCount(i) = 10 Then blnPushed(i) = True '连续按下 30 ms 或以上,确认状态
Else
intCount(i) = 0 '检测到放开状态,重新计数
blnPushed(i) = False
End If
BytStatus = BytStatus \ 2 '右移一位,以检查下一个按钮状态
Next i
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货