-
December 26th, 2006, 05:22 AM
#1
Trying to catch arrows keydown events
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.
-
December 27th, 2006, 04:50 AM
#2
Re: Trying to catch arrows keydown events
Code:
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);
}
If you think you CAN, you can, If you think you CAN'T, you are probably right.
Have some nice Idea to share? Write an Article Online or Email to us and You may WIN a Technical Book from CG.
-
December 27th, 2006, 05:15 AM
#3
Re: Trying to catch arrows keydown events
This works well.
Thank you very much.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|