Adding a new ShortCut to the Delphi IDE is not too difficult, because the open tools API provides a service for this. I am trying to do something more complex: add Wordstar as an optional ShortCut:
I want something to happen when the user clicks
Shift + Ctrl + H followed by one X key
where X should work regardless of the state of the Shift key.
This is my code:
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;
So, if I set ShiftState: = [ssCtrl] by clicking
Ctrl + HX
calls my TwoKeyBindingHandler method.
But with ShiftState: = [ssShift, ssCtrl] click
Shift + Ctrl + HX
doing nothing.
Oddly enough, when specifying ShiftState: = [ssShift, ssCtrl] (which should only affect the first key) by pressing
Shift + Ctrl + H Shift + X
calls my TwoKeyBindingHandler method, although the second ShortCut is added without a modifier key.
Any idea? Perhaps this is a known limitation / bug of the Delphi IDE / Open Tools APIs? Is a workaround known?
I tried this in Delphi 2007 and Delphi 10 Seattle, no difference.