Solved

keyboard events in controls

Posted on 1998-12-29
4
203 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Enroll in June's Course of the Month

June's Course of the Month is now available! Every 10 seconds, a consumer gets hit with ransomware. Refresh your knowledge of ransomware best practices by enrolling in this month's complimentary course for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

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…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

687 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