如何使用ToolsApi将键绑定Shift Ctrl H X添加到Delphi IDE?
将新的ShortCut添加到Delphi IDE并不困难,因为Open Tools API为此提供了一项服务.我正在尝试一些显然更复杂的东西:像其他ShortCut一样添加Wordstar:
我想在用户按下时发生一些事情 按Ctrl H后跟单键X. 无论Shift键的状态如何,X都应该工作. 这是我的代码: procedure TGxKeyboardBinding.BindKeyboard(const BindingServices: IOTAKeyBindingServices); const DefaultKeyBindingsFlag = kfImplicitShift + kfImplicitModifier + kfImplicitKeypad; var GExpertsShortcut: Byte; ShiftState: TShiftState; FirstShortCut: TShortCut; SecondShortCut: TShortCut; begin GExpertsShortcut := Ord('H'); ShiftState := [ssShift,ssCtrl]; FirstShortCut := ShortCut(GExpertsShortcut,ShiftState); SecondShortCut := ShortCut(Ord('X'),[]); BindingServices.AddKeyBinding([FirstShortCut,SecondShortCut],TwoKeyBindingHandler,nil,DefaultKeyBindingsFlag,'',''); end; 所以,如果我按下ShiftState:= [ssCtrl] Ctrl H X. 调用我的TwoKeyBindingHandler方法. 但是用ShiftState:= [ssShift,ssCtrl]按下 Shift Ctrl H X. 什么也没做. 奇怪的是,当指定ShiftState:= [ssShift,ssCtrl](这应该只影响第一个键)时按 Shift Ctrl H Shift X. 调用我的TwoKeyBindingHandler方法,即使添加了第二个ShortCut没有修饰键. 任何的想法?这可能是Delphi IDE / Open Tools API的已知限制/错误吗?有一个已知的解决方法吗? 我在Delphi 2007和Delphi 10 Seattle中尝试过,没有区别. 解决方法
您应该能够使用GetKeyState函数来完成它.
该程序有两个操作 – 将其视为打开下拉菜单项.当按下ctr-shift-h时,您的程序将需要标记“菜单”现在已打开,并且后续按键将激活选项或在按下无效键时关闭“菜单”. function IsKeyDown(const VK: integer): boolean; begin IsKeyDown := GetKeyState(VK) and $8000 <> 0; end; procedure Form1.OnkeyDown(...) begin if Not H_MenuOpen then if IsKeyDown(vk_Control) and IskeyDown(vk_Shift) and IsKeyDown(vk_H) then begin //Some Boolean in the form H_MenuOpen:=True; //Will probably need to invalidate some parameters here so that //no control tries to process the key exit; end; if H_MenuOpen then begin if key=vk_X then begin //x has been pressed *Your code here* //possibly invalidate some of the params again exit; end; //Nothing valid H_MenuOpen:=False; end; 结束; (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |