1

As described here, RichEdit controls have a lot of built-in shortcuts for various functions.

I have TRichEdit controls in a Delphi 7 application where I would like to remove some (but probably not all) of those shortcuts. There is no such method described in msdn.

I am currently simply using OnKeyDown and OnKeyUp event handlers for this purpose, but this isn't a very elegant solution, since I have to add code for every TRichEdit control, and often I'm adding OnKeyDown and OnKeyUp event handlers only for this.

I would like to implement a more elegant solution that deals with those shortcuts globally, like using an interceptor class, but I don't know how to intercept and discard those shortcuts. Any ideas?

TLama
  • 75,147
  • 17
  • 214
  • 392
jedivader
  • 828
  • 10
  • 23

1 Answers1

1

You could add your own shortcut handlers that do nothing. Add an action list and add an action. Use the action's ShortCut and SecondaryShortCuts properties to hijack the shortcuts you are targeting. Add on OnExecute handler for the action that does nothing, or perhaps beeps to indicate an un-handled short cut.

I don't know for sure that this will work having never tried it, but I believe it should.

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
  • It seems to be working, although I don't like the approach very much. What shortcut would you write to handle the CTRL+LeftSHIFT and CTRL+RightSHIFT shortcuts though? – jedivader Feb 22 '14 at 19:58
  • I don't understand. Those are not shortcuts. – David Heffernan Feb 22 '14 at 20:00
  • 1
    They are in the RichEdit control, see [this](http://msdn.microsoft.com/en-us/library/windows/desktop/bb787873%28v=vs.85%29.aspx#rich_edit_shortcut_keys). They change the alignment in RTL BiDi mode. Which is pretty awful if you ask me, for example CTRL+SHIFT can be used to change the input language. – jedivader Feb 22 '14 at 20:03
  • OK, did not know that. I don't think my suggestion is going to help. I'm curious though. Why do you want to make this control less functional. – David Heffernan Feb 22 '14 at 21:06
  • Well, the app the control's used in allows only style and color formatting. The user shouldn't be able to make superscript/subscript text, change the line height or the alignment. And CTRL+SHIFT is the most awful idea for a shortcut I could imagine: that's Window's default keyboard layout switching shortcut, and it can even be assigned to switch the input language. I'm not removing all of the shortcuts, only about a dozen of them or so. Also, some of the shortcuts are already assigned to menus in my app. Plus I don't like not having control (pun intended) over my controls. – jedivader Feb 23 '14 at 11:34