我正在制作一个程序,其中我需要设置多个可由用户按下的热键。我这样声明了热键:
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