[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Problem intercepting KeyDown for arrow keys

Posted on 1997-06-09
7
Medium Priority
?
524 Views
Last Modified: 2008-03-06
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
Comment
Question by:quetz
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 3

Expert Comment

by:ChrisLewis
ID: 1427000
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
 
LVL 2

Accepted Solution

by:
weekee earned 300 total points
ID: 1427001

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
 

Author Comment

by:quetz
ID: 1427002
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 3

Expert Comment

by:dansari
ID: 1427003
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
 

Author Comment

by:quetz
ID: 1427004
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
 
LVL 2

Expert Comment

by:PedroMVGomes
ID: 1427005
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
 

Author Comment

by:quetz
ID: 1427006
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question