当我只有一个Form窗体时 把Form的keypreview属性设置为True 时 在form_keydown事件里能响应键盘上的上下左右四个键的操作,但是当我窗体上加上一个commandbutton对象时 就不能响应了。这时焦点始终在commandbutton对象上。

解决方案 »

  1.   

    按钮吃掉了方向键、回车键等,这些都被按钮自己“用”了,并且没向后放行
    你用HOOK吧
      

  2.   

    Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As IntegerPrivate Sub Form_Load()
        Timer1.Interval = 1
        Timer1.Enabled = True
    End SubPrivate Sub Timer1_Timer()
        Dim Res As Long
        Dim iCode As Integer
        For iCode = 0 To 255
            Res = GetAsyncKeyState(iCode)
            If Res = -32767 Then
                Select Case iCode
                    Case 37
                        Debug.Print "left"
                    Case 38
                        Debug.Print "up"
                    Case 39
                        Debug.Print "right"
                    Case 40
                        Debug.Print "down"
                End Select
            End If
        Next iCode
    End Sub
      

  3.   

    happy_sea 能解释一下代码的意思吗
      

  4.   

    楼主自己搜一下GetAsyncKeyState这个API的详细用法就行了。