• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 527
  • Last Modified:

Problem intercepting KeyDown for arrow keys

I've got a form that the user can change the display on with the arrow keys. I have just added three option buttons and now the form no longer receives the KeyDown event for the arrow keys: they just cycle through the option buttons. I've set KeyPreview to True. I've tried subclassing the form and all the controls on the form. None of them are receiving the WM_KEYDOWN message.

Does anyone know how to get the KeyDown event to trigger? Or even where the WM_KEYDOWN message is going? I'd hate to have to put the option buttons in a menu instead just because of this.
0
quetz
Asked:
quetz
1 Solution
 
ChrisLewisCommented:
There are lots of problems in vb with trying to capture various key strokes.  The Arrow keys and option buttons are a known problem.

Do a search in the MS KB to find the exact problems, but I don't believe there's a solution to your problem.

Chris
0
 
weekeeCommented:

Did you wrote the code in the form Keydown event?

Your problem may arise because the option button got the focus. Since the form did not get the focus. Of course the keydown event is not triggered. To solve the problem, at all the options button
GotFocus event, write (me.setfocus) This will force the form to recieve focus all the time.and you should be able to trap the keydown event
0
 
quetzAuthor Commented:
That doesn't work. Not only does the form not receive the focus, you can no longer click on the option buttons to change them.

Quoting the help for GotFocus:
Occurs when an object receives the focus, either by user action, such as tabbing to or clicking the object, or by changing the focus in code using the SetFocus method. A form receives the focus only when all visible controls are disabled.

So apparently if there are visible controls on the form, it cannot receive the focus.

Just had a thought - went and tried it and it didn't work. If you put code in the KeyDown for the option button, it still doesn't receive the arrow keys. However, when I press other keys both the form and the option button receive KeyDown events. This implies the WM_KEYDOWN message is getting intercepted farther upstream. Any other ideas?
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
dansariCommented:
You could try using Microsoft Spy++ (if you have Visual C++) to see what messages each window gets when you press the keys.

Otherwise, you could try using a subclassing control (or subclass the form and/or option button using AddressOf and a WindowProc if you have VB5) to subclass the form/option button, to see if they get any messages.
0
 
quetzAuthor Commented:
I subclassed the form and the option buttons using Desaware's Spyworks. Nothing on the form that I can get an hDc for seems to be getting the WM_KEYDOWN message. Is there a different message I should be looking for?
0
 
PedroMVGomesCommented:
i think the problem is quiet easy, try repeating the code you puted in the forms KeyDown event in all the option buttons KeyDown events.
I think this shoud work.

Note that you should use the keydown event together with the keyup one, because only then you know that the user has realesed the key.
0
 
quetzAuthor Commented:
As I mentioned before, if I put the code in the option button's KeyDown event it also does not fire for the arrow keys.
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now