Click to See Complete Forum and Search --> : Trying to catch arrows keydown events


efkefk
December 26th, 2006, 05:22 AM
Hello.

I am able to do that by overriding "ProcessCmdKey", but I have problem to detect "shift + arrow" or "ctrl + arrow" keydown event (I need also to be able to detect that). So that would be much easier if I could catch the event in the main form keydown event (Form1_KeyDown) !

I read that setting KeyPreview to true should be the solution. So I added this line: this.KeyPreview = true;
But I am still not able to catch the arrow keydown event, when the focus is on a button.

It there a way to catch arrow keydown events into the main form keydown event (Form1_KeyDown) ?

Or is it an obligation to override "ProcessCmdKey" ?

If the lonely way is to override "ProcessCmdKey", is it possible to catch also "shift + arrow" and "ctrl + arrow" from there ?

Thank you.

Andy Tacker
December 27th, 2006, 04:50 AM
const int WM_KEYDOWN = 0x100;
const int WM_SYSKEYDOWN = 0x104;
protected override bool ProcessCmdKey(ref Message m, Keys keyCode)
{
if ((m.Msg == WM_KEYDOWN) || (m.Msg == WM_SYSKEYDOWN))
{
switch (keyCode)
{
case Keys.F | Keys.Control:
//do something;
break;
case Keys.F5:
//do something;
break;
case Keys.Control | Keys.F10:
//do something;
break;
}
}
return base.ProcessCmdKey(ref m, keyCode);
}

efkefk
December 27th, 2006, 05:15 AM
This works well.
Thank you very much.