我正在尝试使用以下循环找到设置热键的方法:
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)。但是,我无法做到这一点,因为它应该是 Keys.A,Keys.B,Keys.C等等。
这可以用我上面的当前代码吗?
答案 0 :(得分:0)
我刚刚得到它! :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