How to get arrow keys?

  • Thread starter Richard Lewis Haggard
  • Start date
R

Richard Lewis Haggard

I have a user control for which I'm trying to intercept arrow keys. I've
subscribed to both the KeyDown and KeyPress events. Normal keys are
delivered through the KeyPress event handler but arrow keys are not
delivered here. They do arrive at the KeyDown event but only if the control
key is also down. What am I doing wrong?
 
C

Chris Taylor

Hi,

Controls assume that the arrow are used to navigate between controls. By
handling the PreviewKeyDown event and setting the
PreviewKeyDownEventArgs.IsInputKey to true when the
PreviewKeyDownEventArgs.KeyCode is one of the arrow keys you are interested
in, allows the message to be handled by the KeyDown/KeyUp events.

Hope this helps
 
R

Richard Lewis Haggard

That's better but it still isn't working. The system is still getting in and
overriding my own set focus commands.

An arrow key is being handled in a manner much like it would with an array
of radio buttons within a group. Up and left arrows go to the previous
control in the Z order. Down and right shift focus to the control next in
the Z order despite the fact that the program is setting the TabStop
property of the windows to false.

The PreviewKeyDown event is, indeed, fired on key although the IsInputKey is
false, not true for cursor keys so I can now detect the user's cursor keys.
I then set the focus to the appropriate control but the system then
immediately turns around and sets it to the control it wants to. How can I
stop the system from setting focus?

--
Richard Lewis Haggard
www.Haggard-And-Associates.com

Chris Taylor said:
Hi,

Controls assume that the arrow are used to navigate between controls. By
handling the PreviewKeyDown event and setting the
PreviewKeyDownEventArgs.IsInputKey to true when the
PreviewKeyDownEventArgs.KeyCode is one of the arrow keys you are
interested in, allows the message to be handled by the KeyDown/KeyUp
events.

Hope this helps
 
C

Chris Taylor

Hi,

Maybe you can explain what it is that you what to achieve, are you trying to
control the navigation programatically? If so then you should be looking at
the ProcessDialogChar/ProcessDialogKey virtual functions.

--
Chris Taylor
http://dotnetjunkies.com/weblog/chris.taylor


Richard Lewis Haggard said:
That's better but it still isn't working. The system is still getting in
and overriding my own set focus commands.

An arrow key is being handled in a manner much like it would with an array
of radio buttons within a group. Up and left arrows go to the previous
control in the Z order. Down and right shift focus to the control next in
the Z order despite the fact that the program is setting the TabStop
property of the windows to false.

The PreviewKeyDown event is, indeed, fired on key although the IsInputKey
is false, not true for cursor keys so I can now detect the user's cursor
keys. I then set the focus to the appropriate control but the system then
immediately turns around and sets it to the control it wants to. How can I
stop the system from setting focus?
 
R

Richard Lewis Haggard

Thanks. That is precisely what I am trying to achieve. I want the user to be
able to use a right arrow to go to the control to the right of the current
control, up arrow to go to the one above and so on. I will try to make use
of the ProcessDialogxxx functions and see if that will stop the system from
using Z order to set focus to a control despite my own processing of the
event.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top