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

影响keyData的ProcessCmdKey处理的断点

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

    有人能解释为什么在ProcessCmdKey方法中按下Alt+右箭头键时会触发对Alt+左箭头键的检查吗?当我最初编写这个方法时,一切都正常工作。我开始质疑我所有的密钥处理程序,但想知道是否有很好的解释,或者我是否遗漏了什么。所有其他组合键都按预期工作。

    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"
    

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

    [更新]

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

    因此,按位计算, Keys.Right Key.Left And ing with Keys.Left 返回 True

    推荐文章