我正试图找到一种使用以下循环设置热键的方法:
Dim hotKEY(1) as string
Dim tmpKey as new Keys
Dim chosenLetter As Char = "B"
hotKEY(0) = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
hotKEY(1) = "CTRL"
For Each Letter In hotKEY(0).ToCharArray()
If chosenLetter = Letter Then
tmpKey = Asc(Letter)
Exit For
End If
Next
If hotKEY(1) = "SHIFT" Then 'shift
RegisterHotKey(Me.Handle, 100, MOD_SHIFT, tmpKey)
ElseIf hotKEY(1) = "CTRL" Then 'control
RegisterHotKey(Me.Handle, 100, MOD_CONTROL, tmpKey)
ElseIf hotKEY(1) = "ALT" Then 'alt
RegisterHotKey(Me.Handle, 100, MOD_ALT, tmpKey)
ElseIf hotKEY(1) = "WIN" Then 'windows key
RegisterHotKey(Me.Handle, 100, MOD_WIN, tmpKey)
End If
在上面的代码中,tmpKey将是所选的键字母(A-Z/0-9)。但是,我不能这样做,因为它应该是键.A、键.B、键.C等。
这可能与我上面的当前代码有关吗?
我刚刚拿到了!:o)
Dim hotKEY(1) as string
Dim tmpKey as new Keys
Dim chosenLetter As Char = "B"
hotKEY(0) = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
hotKEY(1) = "CTRL"
For Each Letter In hotKEY(0).ToCharArray()
If chosenLetter = Letter Then
tmpKey = Asc(Letter)
Exit For
End If
Next
If hotKEY(1) = "SHIFT" Then 'shift
RegisterHotKey(Me.Handle, 100, MOD_SHIFT, tmpKey)
ElseIf hotKEY(1) = "CTRL" Then 'control
RegisterHotKey(Me.Handle, 100, MOD_CONTROL, tmpKey)
ElseIf hotKEY(1) = "ALT" Then 'alt
RegisterHotKey(Me.Handle, 100, MOD_ALT, tmpKey)
ElseIf hotKEY(1) = "WIN" Then 'windows key
RegisterHotKey(Me.Handle, 100, MOD_WIN, tmpKey)
End If