【问题标题】:Loop through alphbet for hotkey循环遍历热键的字母表
【发布时间】:2013-08-15 13:03:34
【问题描述】:

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

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 等

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

【问题讨论】:

    标签: vb.net loops foreach to-char registerhotkey


    【解决方案1】:

    嗯,我现在才知道! :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
    

    【讨论】:

      猜你喜欢
      • 2015-01-04
      • 2011-11-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-09-19
      • 1970-01-01
      相关资源
      最近更新 更多