Dim mkey() As Integer
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If UBound(mkey) = 0 Then GoTo l
If mkey(UBound(mkey) - 1) <> KeyCode Then
l:
mkey(UBound(mkey)) = KeyCode
ReDim Preserve mkey(UBound(mkey) + 1) As Integer
mkey(UBound(mkey)) = 0
End If
For i = 0 To UBound(mkey)
If mkey(i) = 37 Then c1.Left = c1.Left - 20
If mkey(i) = 40 Then c1.Top = c1.Top + 20
If mkey(i) = 39 Then c1.Left = c1.Left + 20
If mkey(i) = 38 Then c1.Top = c1.Top - 20
Next i
Dim aaa As String
For i = 0 To UBound(mkey)
aaa = aaa & mkey(i) & " | "
Next
Debug.Print aaa
Form1.Cls
Print aaa
End Sub
Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
For i = 0 To UBound(mkey) - 1
If mkey(i) = KeyCode Then
If UBound(mkey) = 1 Or UBound(mkey) = 0 Then
ReDim mkey(0) As Integer
mkey(0) = 0
Else
For a = i To UBound(mkey) - 1
mkey(a) = mkey(a + 1)
Next a
ReDim Preserve mkey(UBound(mkey) - 1) As Integer
Dim bbb As String
For n = 0 To UBound(mkey)
bbb = bbb & mkey(n) & " | "
Next
Print bbb
End If
End If
Next i
End Sub
Private Sub Form_Load()
ReDim mkey(0) As Integer
End Sub
可以看出,我们的程序没问题,数组删除元素正常,是系统消息机制的影响,没有达到预期的效果,当按下一个键有松开同一个键后,系统自动停止了之前按键的消息重载.此时,数组里一切正常,KEYUP KEYDOWN 事件正常,但是系统代劳的按键消息重载(类似系统记忆之前按下了哪些键没松开)失灵了
Dim mkey() As Integer
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If UBound ...[/quote]
人才啊 我一直在看我的程序那里错了 改了又改还是不对 原来是这个原因。。 我再想想怎么解决
谢啦 你哪位?