Friday, September 9, 2011

How To Capture Keys If KeyDown Event Is Not Firing

To force the KeyDown and KeyUp event to capture keys like left, right, up, and down keys, IsInputKey must be overriden.

Here is the code that will show you how to do it.

Protected Overrides Function IsInputKey(keyData As System.Windows.Forms.Keys) As Boolean
    Select Case keyData
        Case Keys.Left, Keys.Right, Keys.Up, Keys.Down
            Return True
        Case Else
            Return MyBase.IsInputKey(keyData)
    End Select
End Function

If there are keys that are not firing the KeyDown and KeyUp event, just place it after the Keys.Down in the select case statement.

No comments:

Post a Comment