I do one test with a new form and its works.
The problem is when have buttons or edit components. I have assign a 'keydown' event to each component.
Does not exists one way more simple?
Main Topics
Browse All TopicsI need capture keys pressed in my form (contains very panels and flat buttons only) and filter only keys: PGDN, PGUP, DOWN and UP for scroll controling.
It is possible througth procedures od type messages WN_ ?
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Use the KeyPreview property of your form, set it to True
This will trigger all Key related events of your form, wherever the focus might be in your controls
onKeyPressed will trigger when an ASCII key is detected. Meaning 'A', '9', '+', '$', Ctrl keys like Enter or Backspace (see an ascii table for reference of these) but will not react to F1, UP, DOWN and combinations
onKeyDown (or Up) is what you need when you want to react to special keys, and the status of Shift, Control.
Atenor,
epasquier more fully explained what I was saying. However, if you have hot-keys assigned to various buttons, you may need to set up a somewhat generic OnKeyPress event that you can then assign to each of the components other than those buttons. (You can use the same OnKeyPress for multiple components. ;-)
In either case, you are going to have a trade-off regarding how you handle the key presses. If you have the form handle all of them but you want to use the hot-keys (e.g. the "x" of "E&xit" for the Exit function) then you are going ot have to code a more complex event handler. If you code the generic event handler in my second suggestion, then you have a simpler event handler but you have to set the OnKeyPress events of more components to use that event handler.
Yes, if you want something to happen only when you are within a field, the code should be in the component event handler.
If it is a general key capture, it has to be in the form + Keypreview.
Keypreview does not have to be set to false for the components to receive those events when they must.
Both will receive it (the form and the component with focus)
The form will have it before, and can set Key := 0 in order to deactivate the component reaction to a key if necessary.
I beleive everything has been said on the subject now.
Business Accounts
Answer for Membership
by: 8080_DiverPosted on 2009-09-24 at 13:03:02ID: 25417241
It would probably be easier to put an On Key Press event handler on your form. THat would let you capture any keys being pressed while your form (or any of its components) has focus. You could then set up a CASE statement that would change any keys other than <PageUp>, <PageDown>, <Up>, or <Down> to #07 (the "bell" character).
By the way, when you say "(contains very panels and flat buttons only)" . . . what kind of panels are those?