Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Firemonkey - catching Alt key + character with FromKeyDown

Raphahz

Programmer
Nov 21, 2024
1
I want to capture the sequence of key combination Alt + Character,
where "Character" can be any valid character key from the keyboard, like 'A', 'B', etc.

So far I have this code:


Code:
procedure Tform1.FormKeyDown (Sender: tObject; var Key: Word; var KeyChar: Char; Shift: tShiftState);
     begin
         if ssAlt in Shift then begin
            IsKeyAltDown := True;
            Key := 0;
         end;
         if KeyAltDown then begin
            IsKeyAltDown := False;
             if KeyChar = 'c' then
                DoSomething;       
         end;
     end;

The first 'if' succeeds on detecting Alt key but the second 'if' does not succeed.

Any help will be appreciated.
 
Last edited:
I presume "KeyAltDown" is something valid, and you're intending "IsKeyAltDown". Regardless, you can simplify this a lot compared to what you have. It does seem that "C" versus "c" matters in how the key sequence is read.

Code:
procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  if ssAlt in Shift then
    if Key = Word('C') then
      MessageDlg('Alt + C pressed', mtInformation, [mbOK], 0);
end;
 

Part and Inventory Search

Sponsor

Back
Top