Solved

keyboard events in controls

Posted on 1998-12-29
4
197 Views
Last Modified: 2010-04-04
I have the simplest control:

TMycontrol = class( TCustomControl )
public
   procedure Paint; override;
end;

I place two such controls on the panel and look how they receive keyboard messages (I use WinSpy). What do I see:
When I click the button one control receive WM_KEYUP and other receive WM_KEYDOWN, on the next click first one receive WM_KEYDOWN and second one WM_KEYUP.
0
Comment
Question by:eugenem
  • 2
  • 2
4 Comments
 
LVL 3

Author Comment

by:eugenem
Comment Utility
One more trouble:
When I use only one control, I don't receive WM_KEYDOWN event after click of conrol keys (arrows, etc.) but receive it on any other keys (alphanumeric, etc.) that produce WM_CHAR event.
Spy++ shows that control's window always receive WM_KEYDOWN.
0
 
LVL 20

Expert Comment

by:Madshi
Comment Utility
The keyboard events are sent to the control that has the focus. So when you press arrow keys, probably the focus is changing from one control to the other between the WM_KEYDOWN and the WM_KEYUP message. That's probably why one control gets the WM_KEYUP and the other control gets the WM_KEYDOWN message.

Please look at which control has the focus.

Regards, Madshi.
0
 
LVL 3

Author Comment

by:eugenem
Comment Utility
That's right. So how can I keep focus on my control?
0
 
LVL 20

Accepted Solution

by:
Madshi earned 100 total points
Comment Utility
Implement a message handler for the WM_GetDlgCode message. Here is a part of the code of TMemo:
  ...
  private
    procedure WMGetDlgCode(var Message: TWMGetDlgCode); message WM_GETDLGCODE;
  ...

procedure TCustomMemo.WMGetDlgCode(var Message: TWMGetDlgCode);
begin
  inherited;
  if FWantTabs then Message.Result := Message.Result or DLGC_WANTTAB
  else Message.Result := Message.Result and not DLGC_WANTTAB;
  if not FWantReturns then
    Message.Result := Message.Result and not DLGC_WANTALLKEYS;
end;

Regards, Madshi.
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now