如何代码改变Delphi的快捷键

如果说Delphi的IDE有什么优势的话,那么我想就是它本身就是由Delphi编写而成,因此我们能定制Delphi的IDE环境,通过Delphi的ToolsAPI的Com接口。     
    
            下面这个例子使用IOTAKeyboardBinding接口,实现对快捷键的重新绑定,相关的接口定义见ToolsAPI.pas。源码很简单,相信你一看就懂。该例子用来修改与中文环境冲突的Code     Completion得快捷键,改成Ctrl+Alt+Shift+P和Ctrl+Alt+Shift+O
  1 //EagleBufferList.pas,2002.5.24     
  2    
  3    {     
  4    Pan     Ying,Zero     Studio     
  5    All     Right     Reserved.     
  6    
  7    The     Demo     show     how     to     change     Delphi's     Key     Binding,just     in     Delphi     
  8    press     Ctrl+Alt+Shift+P     to     use     Code     Completion.You     can     contact     me     by     
  9    sending     e-mail     to     me     (panying@sina.com)     
 10    
 11    Some     code     from     Delphi's     ToolsAPI     Demo.     
 12    
 13    Attention:     
 14    This     software     is     provided     'as-is',     without     any     express     or     
 15    implied     warranty.     In     no     event     will     the     author     be     held     liable     
 16    for     any     damages     arising     from     the     use     of     this     software.     
 17    
 18    This     unit     is     free     to     use     but     the     origin     of     this     software     
 19    must     not     be     misrepresented,     you     must     not     claim     that     you     
 20    wrote     the     original     software.     
 21    
 22    Feel     free     to     use     this     component     in     your     product     including     
 23    commercial     applications.     
 24    
 25    If     You     alert     this     component's     code     to     make     it     better,     
 26    please     remember     to     tell     me     about     it     ,     let's     to     make     it     better     
 27    together.     
 28    
 29    This     attention     may     not     be     removed     or     altered     from     any     source     
 30    distribution.     
 31    
 32    Feedback:     
 33    E-Mail:     panying@sina.com     
 34    HomePage:http://myzeroworld.yeah.net     
 35    
 36    Version     1.1     
 37    Remove     some     useless     code.     
 38    Version     1.0     
 39    Initial     Version.     
 40    }     
 41    
 42    unit     EagleBufferList;     
 43    
 44    interface     
 45    
 46    procedure     Register;     
 47    
 48    implementation     
 49    
 50    uses     Windows,     Classes,     SysUtils,Menus,     ToolsAPI,     Controls     ;     
 51    
 52    type     
 53        TBufferList     =     class(TNotifierObject,     IUnknown,     IOTANotifier,     
 54            IOTAKeyboardBinding)             
 55            function     GetBindingType:     TBindingType;     
 56            function     GetDisplayName:     string;     
 57            function     GetName:     string;     
 58            procedure     BindKeyboard(const     BindingServices:     IOTAKeyBindingServices);     
 59        protected             
 60            procedure     CodeCompletion(const     Context:     IOTAKeyContext;     KeyCode:     TShortcut;     
 61                var     BindingResult:     TKeyBindingResult);     
 62        end;     
 63          
 64    resourcestring     
 65        sBufferList     =     'Eagle''s     Buffer     List';         
 66    
 67    //register     this     key     binding     
 68    procedure     Register;     
 69    begin     
 70        (BorlandIDEServices     as     IOTAKeyBoardServices).AddKeyboardBinding(TBufferList.Create);         
 71    end;     
 72    
 73    {     TBufferList     }     
 74    
 75    
 76    //the     code     to     bind     key     
 77    procedure     TBufferList.BindKeyboard(const     BindingServices:     IOTAKeyBindingServices);     
 78    begin     
 79        BindingServices.AddKeyBinding([ShortCut(Ord('P'),     [ssShift,     ssCtrl,     ssAlt])],     CodeCompletion,     Pointer(csCodeList     or     csManual));     
 80        BindingServices.AddKeyBinding([ShortCut(Ord('O'),     [ssShift,     ssCtrl,     ssAlt])],     CodeCompletion,     Pointer(csParamList     or     csManual));         
 81    end;     
 82    
 83    //do     code     completion     
 84    procedure     TBufferList.CodeCompletion(const     Context:     IOTAKeyContext;     
 85        KeyCode:     TShortcut;     var     BindingResult:     TKeyBindingResult);     
 86    begin     
 87    
 88        (Context.EditBuffer.TopView     as     IOTAEditActions).CodeCompletion(Byte(Context.Context));     
 89        BindingResult     :=     krHandled;     
 90    
 91    end;     
 92    
 93    function     TBufferList.GetBindingType:     TBindingType;     
 94    begin     
 95        Result     :=     btPartial;     
 96    end;     
 97    
 98    function     TBufferList.GetDisplayName:     string;     
 99    begin     
100        Result     :=     sBufferList;     
101    end;     
102    
103    function     TBufferList.GetName:     string;     
104    begin     
105        Result     :=     'EagleKing.BufferList';       //do     not     localize     
106    end;     
107    
108    end.     
109
posted @ 2008-05-21 13:07  zscy  阅读(447)  评论(0编辑  收藏  举报