Mega Code Archive

 
Categories / Delphi / Ide Indy
 

How to assign multiple or not pre defined shortcuts with a TAction at runtime

Title: How to assign multiple or not pre defined shortcuts with a TAction at runtime uses Menus; procedure TMyForm.AddShortcut(Action: TAction; strShortcut: string; Key: Word; Shift: TShiftState); begin if Assigned(Action) then with Action.SecondaryShortCuts do AddObject(strShortcut, TObject(Menus.ShortCut(Key, Shift))); end; procedure TMyForm.FormCreate(Sender: TObject); begin // you may define the shortcut string at will. // for some keys on your keyboard, you'll have to look for // the "real" keycode (use f.e FormKeyDown to retrieve // the value :) // Some keys are defined in the Windows unit. Look for "VK_xxxxx". AddShortcut(MyAction1, 'CTRL+Numpad1', VK_Numpad1, [ssCTRL]); AddShortcut(MyAction1, 'CTRL+SHIFT++', 187, [ssCTRL, ssSHIFT]); end;