1

我正在尝试找到一种使用以下循环设置热键的方法:

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将是选择的键字母 (AZ/0-9)。但是,我不能这样做,因为它应该是Keys.A、Keys.B、Keys.C 等

这可能与我上面的当前代码有关吗?

4

1 回答 1

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
于 2013-08-15T13:19:55.100 回答