...multiple sowie nicht vordefinierte Shortcuts mit einer TAction zur Laufzeit verknüpfen?

Autor: Loïs Bégué
Homepage: http://www.arpoon.com

Kategorie: VCL

{++++++++++++++++++++++ Deutsch ++++++++++++++++++++++++++++++++++++++++++++
Sie können ein TActionList bzw. TAction benutzen, um verschiedene Shortcuts
einem Menüpunkt oder einem Button zuzuordnen.
Ebenfalls nutzen Sie diesen Tip, um "nicht registrierte" Shortcuts zu nutzen.
Beipiele für 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.
+++++++++++++++++++++++ Français++++++++++++++++++++++++++++++++++++++++++++
Vous pouvez définir des raccourcis multiples pour une action, un menu, un
bouton etc...
De plus, vous pouvez définir de nouveaux raccourcis (non définis par défaut
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;

 

printed from
www.swissdelphicenter.ch
developers knowledge base