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