Solved

keyboard events in controls

Posted on 1998-12-29
4
198 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Send secure, cloud-based, encrypted alerts and maintain HIPAA compliant messaging. Integrates priority & secure messaging into one application. Ensures IT, emergency respondents and healthcare professionals that their critical messages are never mis…

911 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

20 Experts available now in Live!

Get 1:1 Help Now