Solved

Problem intercepting KeyDown for arrow keys

Posted on 1997-06-09
7
516 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 150 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
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!

 
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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

763 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