Solved

keyboard events in controls

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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
oracle global variables 4 70
delphi parse string to params 3 123
How to build JSON File in Delphi 6 3 35
MS Access from Delphi 31 33
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

832 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