Mega Code Archive

 
Categories / Delphi / Ide Indy
 

Assign multiple or not pre defined shortcuts with a TAction at runtime

Title: assign multiple or not pre defined shortcuts with a TAction at runtime? {++++++++++++++++++++++ Deutsch ++++++++++++++++++++++++++++++++++++++++++++ Sie knnen ein TActionList bzw. TAction benutzen, um verschiedene Shortcuts einem Menpunkt oder einem Button zuzuordnen. Ebenfalls nutzen Sie diesen Tip, um "nicht registrierte" Shortcuts zu nutzen. Beipiele fr nicht registrierte Shortcuts: [Numpad 1]..[Numpad 0] [CTRL] + [SHIFT] + [+] ... +++++++++++++++++++++++ English ++++++++++++++++++++++++++++++++++++++++++++ You can use a TActionList/TAction to manage with more than one shortcut, giving your Buttons, Menuitems... more flexibility. You can also register "extended" shortcuts, wich are not in defined in the standard shortcut list. +++++++++++++++++++++++ Franais++++++++++++++++++++++++++++++++++++++++++++ Vous pouvez dfinir des raccourcis multiples pour une action, un menu, un bouton etc... De plus, vous pouvez dfinir de nouveaux raccourcis (non dfinis par dfaut dans les fichiers de Delphi) +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++} 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;