0

我正在制作一个程序,我需要在其中设置多个用户可以按下的热键。我这样声明热键:

Dim index1 As Integer = 0
    Dim hotkeycounter as integer= 0
    For index0 = 0 To mainArr.GetUpperBound(0)
        For index1 = 0 To mainArr.GetUpperBound(1)
            If mainArr(index0, index1) = "" Then
                MsgBox("exited the unregisterhotkey for loop")
                GoTo line1
            End If
            UnregisterHotKey(Me.Handle, hotkeycounter)
            hotkeycounter = hotkeycounter + 1
        Next
    Next
line1:

    hotkeycounter = 0
    For index0 = 0 To mainArr.GetUpperBound(0)
        For index1 = 0 To index1 = 1
            If mainArr(index0, index1) = "" Then
                MsgBox("exited the registerhotkey for loop")
                GoTo line2
            End If
            RegisterHotKey(Me.Handle, hotkeycounter, &H1, index0)
            hotkeycounter = hotkeycounter + 1
            MsgBox("A hotkey has been registered")
            MsgBox(($"{mainArr(index0, index1)} "))
        Next
    Next
line2:

所以基本上热键的命令值是从数组中读出的。我的问题是我无法检测到哪个数组被按下(由'hotkeycounter'定义)。我尝试检测按下哪个热键的代码是:

 Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
    Dim specialcharacter As String
    If m.Msg = WM_HOTKEY Then   

        If commandID = 0 Then
            MsgBox("You pressed the first key combination")
        ElseIf commandID = 1 Then
            MsgBox("You pressed the second key combination")
        ElseIf commandID = 2 Then
            MsgBox("you pressed the third key combination")
        End If
    End If
        MyBase.WndProc(m)
End Sub
4

0 回答 0