Solved

Problem intercepting KeyDown for arrow keys

Posted on 1997-06-09
7
512 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
7 Comments
 
LVL 3

Expert Comment

by:ChrisLewis
Comment Utility
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
Comment Utility

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
Comment Utility
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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 3

Expert Comment

by:dansari
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
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…

744 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now