Solved

keyboard events in controls

Posted on 1998-12-29
4
201 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
ID: 1353531
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
ID: 1353532
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
ID: 1353533
That's right. So how can I keep focus on my control?
0
 
LVL 20

Accepted Solution

by:
Madshi earned 100 total points
ID: 1353534
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
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…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

679 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