Question

ListView.KeyDown <Ctrl> event shows the following:

e   KeyData = LButton | ShiftKey | Control
    base    {KeyData = LButton | ShiftKey | Control}
        Alt false   bool
        Control true    bool
        Handled false   bool
        KeyCode LButton | ShiftKey
        KeyData LButton | ShiftKey | Control
        KeyValue    17
        Modifiers   
        Shift   false   bool
        SuppressKeyPress    false   bool

I don't like the fact that the <ShiftKey> is showing up but the Control key is showing up. On ListView.KeyUp <Ctrl> event shows the following:

-       e   {KeyData = LButton | ShiftKey}
+       base    {KeyData = LButton | ShiftKey}
        Alt false   bool
        Control false   bool
        Handled false   bool
        KeyCode LButton | ShiftKey
        KeyData LButton | ShiftKey
        KeyValue    17
        Modifiers   None
        Shift   false   bool
        SuppressKeyPress    false

What gives it's weird. Look over the web to see if there are any examples of this error but could find nothing. I have tried setting the KeyPreview to true on the hosting form to no avail.

Any input is welcome.

Was it helpful?

Solution

There's no error here, you simply pressed and released the Ctrl key. The debugger just isn't very good at converting the Keys enum to a string. It is confuzzled by that enum having the [Flags] attribute so it tries to map the individual bits in the value to a Key.

So KeyDown = (Keys.Control | Keys.ControlKey) = 0x20011. Which the debugger mangles to
0x20000 = Control
0x00010 = ShiftKey
0x00001 = LButton.

And Keyup = (Keys.ControlKey) = 0x00011. Which the debugger mangles to
0x00010 = ShiftKey
0x00001 = LButton.

Or in other words, ignore what the debugger tells you.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top