473,472 Members | 1,728 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

KeyDown event

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
4 34503
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: bardo | last post by:
I have a Datagrid that is inside a panel. I want to use the keyDown event to reconize the arrow keys. But I have no luck at all. The problem is that the keydown event won't fire at all, unless I...
4
by: Tony | last post by:
I'm building a simple "breakout" style video-game, and I want keyboard control of the paddle. What I need is for an event handler to respond whenever a key is pressed, regardless of what the...
4
by: Anne | last post by:
hie again, i have 3 textbox and i would like the user to go to the next textbox by pressing the 'ENTER' key. i have tried using this: Private Sub txtRequestor_KeyDown(ByVal sender As...
4
by: ShaneO | last post by:
I would like to handle the KeyUp & KeyDown events in the same event handler but can't find how to determine which event was fired - Private Sub ListBox1_KeyUp(ByVal sender As Object, ByVal e As...
1
by: fripper | last post by:
I have a VB 2005 windows app and I want to recognize keydown events. I have a form key down event handler but it does not get control when a key is depressed. In playing around I found that if I...
0
by: tony | last post by:
Hello!! I have a derived class called StringClassEditor which inherit from UITypeEditor listed below. Now to my question in method EditValue in this class I have this statement lb.KeyDown ...
3
by: MLM450 | last post by:
I have a control that handles the KeyDown event but it does not seem to execute when a combination of keys is pressed - like CTRL+Z. If I press CTRL, it executes. If I press Z, it executes. But the...
3
by: win | last post by:
when the cursor is in a textbox, only coding in the keydown event of the textbox triggered, the coding in the keydown event of the form does not triggered! Problem: I need to change a VB6 program...
2
by: Tony Johansson | last post by:
Hello! I have created a Control that consist of a label and a textbox.I have called this class ctlLabelTextbox. public partial class ctlLabelTextbox : UserControl { .... } The class that I...
14
by: raylopez99 | last post by:
KeyDown won't work KeyPress fails KeyDown not seen inspired by a poster here:http://tinyurl.com/62d97l I found some interesting stuff, which I reproduce below for newbies like me. The main...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.