HotKey (Delphi)

From RAD Studio Code Examples
Jump to: navigation, search

Description

To use this example, create a form with a main menu component and a HotKey component. At design time, use the Menu designer to add menu items, including a File menu with subitems that include a New menu item. Add the following code to the OnCreate method of the form and the OnClick event of the File menu item.

Code

procedure TForm1.File1Click(Sender: TObject);
begin
  // Assign hotkey to the menu's File "New" item. 
  New1.ShortCut := HotKey1.HotKey;  
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  // Default to "Ctrl + A"
  HotKey1.Modifiers := [hkCtrl];
  // Don't allow shift or alt
  HotKey1.InvalidKeys := [hcShift, hcAlt];
end;

Uses