Solved

How do I capture the Left Alt key in Application.OnMessage?

Posted on 2002-05-18
5
1,035 Views
Last Modified: 2011-09-20
Hi,

I need to be able to detect keys that are pressed with the Left Alt key in Application.OnMessage.  I have set up a simple test like this with no extra components on the form...

procedure TForm1.FormCreate(Sender: TObject);
begin
  Application.OnMessage := MyMessageHandler
end;

procedure TForm1.MyMessageHandler(var Msg: TMsg; var Handled: Boolean);
begin
  if (Msg.message = WM_KEYDOWN) and (Msg.wParam = Ord('A')) then
  begin
    Handled := True;
    ShowMessage('A pressed');
  end
end;

These key combinations show the message...

A
CTRL + A
Right Alt + A

However, when I press Left Alt + A, I just get a bleep - no message is displayed.  Try it and you'll see.  It seems that key presses with the Left Alt key are ignored by the message handler.  How do I get around this?  I really need to be able to detect key combinations such as Left Alt + A in Application.OnMessage.  I'm using Delphi 4 Pro.

Thanks in Advance,

Richard
0
Comment
Question by:Richard2000
  • 3
5 Comments
 
LVL 33

Accepted Solution

by:
Slick812 earned 50 total points
ID: 7019056
The WM_SYSKEYDOWN message is posted to the window with the keyboard focus when the user holds down the ALT key and then presses another key. So try

if (Msg.message = WM_SYSKEYDOWN) and (Msg.wParam = Ord('A')) then
 begin
   Handled := False;
   ShowMessage('sys A pressed');
 end

 I set handled to false, since this is a SysKeyDown, but setting handled to True, may be better if the if you don't want the system to do anything.
0
 
LVL 9

Expert Comment

by:ginsonic
ID: 7019289
I think That Richard what to know if is Left ( or Right ) AKT key .

Read this :

How to distinguish between the right shift key and the
left shift key in Delphi?

http://www.monbestof.com/fr/view/default.Asp?CustID=4-886021737&ServiceID=4&CurCat=2&ProdID=1175&bp=/fr/tips/default.asp
0
 
LVL 9

Expert Comment

by:ginsonic
ID: 7019291
How you can see for left ALT use
kpLeftAlt = 1 shl 9;

Regards,
Nick
0
 
LVL 9

Expert Comment

by:ginsonic
ID: 7019755
Just curious , the code work just for left ALT or bouth ?
0
 

Author Comment

by:Richard2000
ID: 7020014
Hi ginsonic,

Slick812's code works for Left Alt only.

Richard
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

Title # Comments Views Activity
Mydac connection data base issue 3 139
Path  to current project in Delphi. 2 72
Delphi selector screen 2 69
Convert MS Word document to a PDF file 9 62
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

910 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

19 Experts available now in Live!

Get 1:1 Help Now