By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,921 Members | 1,479 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,921 IT Pros & Developers. It's quick & easy.

KeyDown event

P: n/a
I am trying to detect the keydown of the arrow keys in a
custom control that I am writing. As far as I can tell,
pressing the arrow keys does not fire the KeyDown event
at all. It behaves just like the tab key, passing focus
to the next control in the tab order. The only events
that fire are in the lost focus sequence (leave,
validating, validated, etc.) Any ideas?
Nov 13 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Mike,

Are you attaching to the KeyDown event, or are you overriding the
OnKeyDown method? You might be able to get it in the OnKeyDown method, as
filtering might occur on that level.

If it does not, then you can override the WndProc method of the class
and handle the windows message for the key down event WM_KEYDOWN.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- ni**************@exisconsulting.com

"Mike M" <mi*********@bcbskc.com> wrote in message
news:0b****************************@phx.gbl...
I am trying to detect the keydown of the arrow keys in a
custom control that I am writing. As far as I can tell,
pressing the arrow keys does not fire the KeyDown event
at all. It behaves just like the tab key, passing focus
to the next control in the tab order. The only events
that fire are in the lost focus sequence (leave,
validating, validated, etc.) Any ideas?

Nov 13 '05 #2

P: n/a
I have tried both attaching to the event and overriding
OnKeyDown. Neither one worked. I was hoping that maybe
the Control class' OnKeyDown was maybe filtering out and
interpreting the arrow key, but if that was the case then
overriding (and waiting to call the base class'
OnKeyDown) should have fixed the problem.

I'll try the WndProc method, though. Thanks.
-----Original Message-----
Mike,

Are you attaching to the KeyDown event, or are you overriding theOnKeyDown method? You might be able to get it in the OnKeyDown method, asfiltering might occur on that level.

If it does not, then you can override the WndProc method of the classand handle the windows message for the key down event WM_KEYDOWN.
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- ni**************@exisconsulting.com

"Mike M" <mi*********@bcbskc.com> wrote in message
news:0b****************************@phx.gbl...
I am trying to detect the keydown of the arrow keys in a custom control that I am writing. As far as I can tell, pressing the arrow keys does not fire the KeyDown event
at all. It behaves just like the tab key, passing focus to the next control in the tab order. The only events
that fire are in the lost focus sequence (leave,
validating, validated, etc.) Any ideas?

.

Nov 13 '05 #3

P: n/a
A
"Nicholas Paldino [.NET/C# MVP]" <ni**************@exisconsulting.com> wrote
in message news:eV**************@tk2msftngp13.phx.gbl...
Mike,

Are you attaching to the KeyDown event, or are you overriding the
OnKeyDown method? You might be able to get it in the OnKeyDown method, as
filtering might occur on that level.

If it does not, then you can override the WndProc method of the class
and handle the windows message for the key down event WM_KEYDOWN.


Actuall, I tihnk what you want is to check out the IsInputKey method. IIRC,
there are a couple of methods that determine how certain keys are processed,
and you can override the default and do it yourself, so that the special
keys can be treated as regular keys as opposed to their default as "special
keys." I know there is a way to do this without having to resort to the
WM_KEYDOWN override in WndProc.

-akshay
Nov 13 '05 #4

P: n/a
As it turns out, it is the ProcessCmdKey method. Thanks
for all your help, though. It got me going in the right
direction. Here's an example...

protected override bool ProcessCmdKey(ref Message m, Keys
keyData)
{
bool blnProcess = false;

if (keyData == Keys.Right || Keys.Down)
{
// Process the keystroke
blnProcess = true;
}
else if (keyData == Keys.Left || Keys.Up)
{
// Process the keystroke
blnProcess = true;
}

if (blnProcess == true)
return true;
else
return base.ProcessCmdKey(ref m, keyData);
}

-----Original Message-----
I am trying to detect the keydown of the arrow keys in a
custom control that I am writing. As far as I can tell,
pressing the arrow keys does not fire the KeyDown event
at all. It behaves just like the tab key, passing focus
to the next control in the tab order. The only events
that fire are in the lost focus sequence (leave,
validating, validated, etc.) Any ideas?
.

Nov 13 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.