• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1140
  • Last Modified:

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

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
Richard2000
Asked:
Richard2000
  • 3
1 Solution
 
Slick812Commented:
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
 
ginsonicCommented:
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
 
ginsonicCommented:
How you can see for left ALT use
kpLeftAlt = 1 shl 9;

Regards,
Nick
0
 
ginsonicCommented:
Just curious , the code work just for left ALT or bouth ?
0
 
Richard2000Author Commented:
Hi ginsonic,

Slick812's code works for Left Alt only.

Richard
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now