RAD Studio VCL Reference
ContentsIndex
PreviousUpNext
Menus.ShortCutToKey Function

Returns the key code and shift state of a menu shortcut.

Pascal
procedure ShortCutToKey(ShortCut: TShortCut; var Key: Word; var Shift: TShiftState);
C++
ShortCutToKey(TShortCut ShortCut, Word Key, TShiftState Shift);

Call ShortCutToKey to parse a menu shortcut into its virtual key code and shift state parts. 

ShortCut is the value of the menu shortcut. 

Key returns the virtual key code (Menus version) or Qt key code (QMenus version) for the key. 

Shirt returns the associated combination of Shift, Ctrl, and Alt keys.  

C++ Examples: 

 

/*
The following code redefines the ShortCut of CloseCommand if
the original short cut used the [ssCtrl] shift state.
*/
void __fastcall TForm1::Button1Click(TObject *Sender)
{
  Word TheKey;

  TShiftState TheShiftState;

  ShortCutToKey(CloseCommand->ShortCut, TheKey, TheShiftState);
  if (TheShiftState.Contains(ssCtrl))
    CloseCommand->ShortCut = ShortCut(Word('C'), TShiftState() << ssShift);}

void __fastcall TForm1::CloseCommandClick(TObject *Sender)
{
  MessageDlg(
    "The Close command has been selected.",
    mtInformation,
    TMsgDlgButtons() << mbOK,
    0);
}

void __fastcall TForm1::FormCreate(TObject *Sender)
{
  CloseCommand->ShortCut =
    ShortCut(Word('C'), TShiftState() << ssCtrl);
}

 

Delphi Examples: 

{
The following code redefines the ShortCut of CloseCommand if
the original short cut used the [ssCtrl] shift state.
} 
procedure TForm1.Button1Click(Sender: TObject);
var
  TheKey: Word;
  TheShiftState: TShiftState;
begin
  Menus.ShortCutToKey(CloseCommand.ShortCut, TheKey, TheShiftState);
  if TheShiftState = [ssCtrl] then
   CloseCommand.ShortCut := ShortCut(Word('C'), [ssShift]);
end;

procedure TForm1.CloseCommandClick(Sender: TObject);
begin
  MessageDlg('The Close command has been selected.', mtInformation, [mbOk], 0);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  CloseCommand.ShortCut := Menus.ShortCut(Word('C'), [ssCtrl]);
end;

 

Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!