代码之家  ›  专栏  ›  技术社区  ›  AMissico

影响keydata的processCmdKey处理的断点

  •  1
  • AMissico  · 技术社区  · 16 年前

    有人能解释为什么在processCmdkey方法中按alt+right arrow键时会触发检查alt+left arrow键吗?当我最初编码这个方法时,一切都正常。我开始质疑我所有的关键处理人员,但我想知道是否有一个很好的解释,或者我错过了什么。所有其他组合键按预期工作。

    Protected Overrides Function ProcessCmdKey(ByRef msg As Message, ByVal keyData As Keys) As Boolean
        If (keyData And Keys.Alt) = Keys.Alt Then
            If (keyData And Keys.Left) = Keys.Left Then
                'when Alt+Right key is pressed
                '   this executes, except when a breakpoint is set anywhere within this method
                '   this still executes in released code
                Debug.WriteLine("WTF!")
            End If
        End If
        Return MyBase.ProcessCmdKey(msg, keyData)
    End Function
    

    解决方法是检查按键 If keyData = (Keys.Alt Or Keys.Left) Then

    [更新] 啊,我明白了。谢谢米奇。我查过了,但没查到。

    ? convert.ToString(Keys.Left, 2)
    "100101"
    ? convert.ToString(Keys.Right,2)
    "100111"
    

    仍然想知道为什么点击断点会改变行为。

    [更新] 再次感谢米奇。因为它对你来说不可复制,所以我怀疑solutions.suo文件已损坏。我删除了这个文件,现在点击断点没有影响。

    1 回复  |  直到 16 年前
        1
  •  0
  •   Mitch Wheat    16 年前
    Keys.Left  = 37 = 32 + 4     + 1
    Keys.Right = 39 = 32 + 4 + 2 + 1
    

    按位计算, Keys.Right 包括 Key.Left . 因此 And 使用 Keys.Left 返回 True 在任何一种情况下。

    推荐文章