The Case of Swallowed Key Combinations

My officemate asked my why his key combination was not working, when I looked at the application I told him that it might be because the active control is currently in read-only mode and that it might be rejecting those key combo. However, he refuted that if that were the case, his other key combinations should also not work; and also pointed out that I might be right with my initial assessment of read only fields rejecting key strokes when he made his key combinations on a textbox which isn't read only. He has, by the way, enabled the KeyPreview property of the form to capture those keystrokes first before the any controls. It was kind of odd, that some key combinations were available regardless of the readonly property status of an active control.

I did a quick test to observe the KeyEventArgs during KeyDown event with the following code:

       public Form1()

        {

            InitializeComponent();

 

            this.KeyDown+=new KeyEventHandler(this.OnFormKeyDown);

 

        }


  

        private void OnFormKeyDown(object sender, KeyEventArgs e)

        {

 

            this.txtKeyCode.Text = e.KeyCode.ToString();

            this.txtKeyData.Text = e.KeyData.ToString();

            this.txtKeyModifiers.Text = e.Modifiers.ToString();

            this.txtKeyValue.Text = e.KeyValue.ToString();

            this.txtHandled.Text = e.Handled.ToString();

         }



After running the program I've observed the following:

1.) For the key combinations : CTRL+L(my officemates key combo), CTRL+E, CTRL+J, and CTRL+L, were not displaying the correct KeyData

2.) Oddly it(KeyData) was the same as pressing only the CTRL key


It's as if when those key combinations are made the KeyEventArgs are not filled correctly. Hence I couldn't do the following check:


 if (e.Control && (e.KeyCode == Keys.L)){ //do something }


UPDATED: Comgen, correctly noted that it wasn't a KeyValue returning a constant 17, but actually returns nothing ie:the KeyEventArgs.KeyValue isn't getting a new value but the same value from before. The reason I concluded before that it was a constant 17 because I did a CTRL, then +L, since the previous KeyValue property was 17(for CTRL), the next time I pressed L the KeyValue property remained the same. However, if you pressed any CTRL+combination(except those questionable 4), and without depressing CTRL press either of those 4 letters (ie. CTRL + L) then the previous KeyValue will still remain. I am really stressing this one a bit. :P






Published 02-22-2007 6:13 PM by bonskijr

Comments

# re: The Case of Swallowed Key Combinations

"Because the KeyCode property is a constant 17 for either of those combinations"

its not registered as 17, actually it does not register anything. try doing this. PRESS CTRL + A Then Press CTRL + J but dont depressed the CTRL you will notice that the KeyCode property is 65(A) and not 17(CTRL).

Thursday, February 22, 2007 5:42 PM by Comgen

# re: The Case of Swallowed Key Combinations

actually I don't have any problems with other combinations it's just those 4 combo..

it's easy to reproduce, just place 4 textbox for(KeyCode,KeyData,KeyValue and modifiers) and make them all read-only. Make the Form's KeyPreview property to True then subscribe to the onKeyDown event of the Form, then paste that code from my sample and you'll get the idea.

Friday, February 23, 2007 8:40 PM by bonskijr

# re: The Case of Swallowed Key Combinations

Yaps already have encountered this then too.

What i am talking about is your statement

      "Because the KeyCode property is a constant 17 for either of those combinations"

I just want to reiterate that those 4 keys really dont return KeyCode 17, but nothing at all. Because this will confuse others.

try doing this. PRESS CTRL + A Then Press CTRL + J but dont depressed the CTRL you will notice that the KeyCode property is 65(A) and not 17(CTRL).

I wrote this to prove that its not returning 17.

Anyway still have no fix for this scenario. those 4 keys are very special. i tried to google then if windows have something special about this 4 but to no luck, i found nothing.

Sunday, February 25, 2007 5:28 PM by Comgen

# The Case of Swallowed Key Combinations

You've been kicked (a good thing) - Trackback from DotNetKicks.com

Sunday, February 25, 2007 11:03 PM by DotNetKicks.com

# Tramadol c.o.d..

Tramadol 180. Tramadol. Cheap tramadol prescriptions online.

Wednesday, June 03, 2009 5:10 PM by Tramadol.

# Phentermine.

Phentermine obesity. No prescription phentermine. Phentermine without prescription. Phentermine. Phentermine weight loss pill. Order phentermine. Free phentermine.

Friday, June 05, 2009 4:57 PM by Danger of phentermine.

# Vicodin no prescription.

Vicodin detox.

Saturday, June 06, 2009 5:49 PM by Vicodin.

# Hydrocodone.

Hydrocodone. Hydrocodone apap. Hydrocodone addiction. Norco hydrocodone. Snorting hydrocodone. Hydrocodone apap 5 500.

Monday, June 08, 2009 8:03 PM by I took hydrocodone thru entire pregnancy.

# Adderall treating anxiety in adults.

Adderall side effects. Adderall treating anxiety in adults. Adderall. Where to buy adderall.

Friday, June 12, 2009 12:05 AM by Adderall.