Bug with KeyDown event.

  • Hi,

    I'm using the control to monitor and control keyboard events and have noticed some undesirable issues with the KeyDown event.

    The following code snipits assume a form with a TextDynamic control named "TD"

    1. Take the following code as an example:

    Code
    Private Sub TD_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TD.KeyDown        Debug.Write("KD: ")        Debug.WriteLine(e.Shift.ToString)    End Sub

    When trapping the key down event I have noticed that typing the keys slowly with the above code will produce one event for each key. i.e. typing "123" slowly will result in 3 KeyDown events being raised. This is of course correct.

    However, when the same keys ("123") are pressed very quickly in succession more than the 3 events are raised. This is not correct.

    * Also the Shift key being held down is not recognised. It always come through as false. *

    2. Take as example the following code:

    Code
    Private Sub TD_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TD.KeyDown        Debug.WriteLine("KD: ")        e.Handled = True        e.SuppressKeyPress = True    End Sub

    Now we are handling and suppressing the KeyDown events. But for each key being pressed (it doesn't matter the speed the keys are pressed) there are 2 KeyDown events being raised. This is not correct.

    However if we now insert the KeyUp event and handle it as below;

    Code
    Private Sub TD_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TD.KeyUp
            e.Handled = True
            e.SuppressKeyPress = True
        End Sub

    only one KeyDown event will be fired; this is what is expected from the KeyDown event without having to provide the KeyUp event and suppress that event.

    Can you please let me know if this is a known issue and/or if a fix is also available for these issues (especially the Shift key problem as this is really needed for my application).

    Thanks,

    Kurt
    [/code]

    • Offizieller Beitrag

    Hi,

    the problem with shift will be fixed in next release.

    The problem with the double KeyUp seems to be new to FrameWork 2. In future it will internally set the SuppressKeyPress flag and reimplement it so it should work as expected.

    Julian