Solved

Problem intercepting KeyDown for arrow keys

Posted on 1997-06-09
7
514 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
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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Suggested Solutions

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

809 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