Working with KeyBoard Binding |
|
axsoft
版主 ![]() ![]() ![]() ![]() ![]() ![]() 發表:681 回覆:1056 積分:969 註冊:2002-03-13 發送簡訊給我 |
Working with KeyBoard Binding 資料來源: www.delphi3000.com How to set your own shortcut keys while working with delphi editor?
If you want your own piece of shortcut key to perform a certain action for you then this code will help {Include this unit in a delphi package, and install the package. Now, if you press ctrl + d you will get the 'This was written by Subha Narayanan' in your editor window. The actual process is very simple. We use the interface TNotifier Object and IOTAkeyboardbinding to create our own interface. our main key to perform this action is the procedure 'Dupline' }
--------------------------------------------------------------------------------
unit DupLineBinding; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, menus, ToolsApi; type TDupLineBinding = class(TNotifierObject, IOTAKeyboardBinding) private { Private declarations } protected { Protected declarations } public { Public declarations } Procedure DupLine(Const Context: IOTAKeyContext; KeyCode: TShortCut; Var BindingResult : TKeyBindingResult); {IOTAKeyBoardBinding} function GetBindingType : TBindingType; function GetDisplayName : string; function GetName : string; procedure BindKeyboard(const BindingServices: IOTAKeyBindingServices); published { Published declarations } end; procedure Register; implementation procedure Register; begin (BorlandIDEServices as IOTAKeyBoardServices).AddKeyBoardBinding(TDupLineBinding.Create); end; function TDupLineBinding.GetBindingType: TBindingType; begin Result := btPartial; end; function TDupLineBinding.GetDisplayName ; begin Result := 'Subha Line Binding'; {The way it shoudl appear in the delphi ide editor window} end; function TDupLineBinding.GetName ; begin Result := 'sn.dupline'; {Should be unique} end; procedure TDupLineBinding.DupLine(Const Context: IOTAKeyContext; KeyCode: TShortCut; Var BindingResult : TKeyBindingResult); var ep : IOTAEditPosition; eb : IOTAEditBlock; r, c : Integer; begin {Actual place where the writting into editor takes place} try ep := Context.EditBuffer.EditPosition; ep.Save; r := ep.Row; c := ep.Column; eb := Context.EditBuffer.EditBlock; ep.MoveBOL; eb.Reset; eb.BeginBlock; eb.Extend(Ep.Row 1, 1); eb.EndBlock; eb.Copy(False); ep.MoveBOL; ep.Paste; ep.Move(r,c); finally ep.Restore; end; BindingResult := krHandled; end; procedure TDupLineBinding.BindKeyboard(const BindingServices: IOTAKeyBindingServices); {Here we specify the shortcut key which should do the action} begin BindingServices.AddKeyBinding([Shortcut(Ord('D'),[ssCtrl])],DupLine,nil); end; end.網路志工聯盟----Visita網站http://www.vista.org.tw ---[ 發問前請先找找舊文章 ]--- 發表人 - axsoft 於 2003/02/11 14:48:57 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |