PeterPanettone 157 Posted 5 hours ago (edited) At run-time, select any text in a TRichEdit and press CTRL+I: The selected text will be replaced by a TAB "character," which has the same effect as pressing the TAB key. BTW, the same effect occurs in Notepad. Is there a way to prevent this? Delphi 12.2 Windows 11 x64 Edited 5 hours ago by PeterPanettone Share this post Link to post
DelphiUdIT 154 Posted 5 hours ago (edited) I don't think you can do something, except to capture the keyboard in the control (or in the OnKey... of the Form with the KeyPreview property active). In the event intercept the combination key and put tha value to ZERO (0). Take care that you must try wich event you can use ... not all the OnKey... events are the same scope. Edit: you can see an example how to implement the OnKeyDown event in a TControl descendent here: https://docwiki.embarcadero.com/RADStudio/Athens/en/Responding_to_Key-down_Messages Bye Edited 5 hours ago by DelphiUdIT Share this post Link to post
PeterPanettone 157 Posted 4 hours ago Even when KeyPreview = True, setting Key := 0; in FormKeyDown does not prevent this strange effect: procedure TformTextEditor.FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); begin if (Key = Ord('I')) and (Shift = [ssCtrl]) then begin CodeSite.Send('TformTextEditor.FormKeyDown: '); Key := 0; end end; Share this post Link to post
PeterPanettone 157 Posted 4 hours ago (edited) Using KeyPreview, I have even tried the following trick: procedure TformTextEditor.FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); begin if (Key = Ord('I')) and (Shift = [ssCtrl]) then begin CodeSite.Send('TformTextEditor.FormKeyDown: '); Key := 255; end end; And then in RichEditKeyDown: if (Key = 255) and (Shift = [ssCtrl]) then begin CodeSite.Send('RichEditKeyDown: '); Key := 0; // does not prevent TAB output! end Edited 4 hours ago by PeterPanettone Share this post Link to post
DelphiUdIT 154 Posted 4 hours ago May be you should use 'I' and 'i' (case sensitive) in the events ? Share this post Link to post
PeterBelow 235 Posted 3 hours ago 1 hour ago, PeterPanettone said: Even when KeyPreview = True, setting Key := 0; in FormKeyDown does not prevent this strange effect: procedure TformTextEditor.FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); begin if (Key = Ord('I')) and (Shift = [ssCtrl]) then begin CodeSite.Send('TformTextEditor.FormKeyDown: '); Key := 0; end end; You have to use OnKeyPress and check for Ctrl down there. The behaviour you see is perfectly OK, by the way. Ctrl-<letter> combos have created control characters since the ancient days of DOS, and ^I (#9) is the TAB character... 1 Share this post Link to post
PeterPanettone 157 Posted 3 hours ago 3 minutes ago, PeterBelow said: Ctrl-<letter> combos have created control characters since the ancient days of DOS, and ^I (#9) is the TAB character... Thanks for the information. Share this post Link to post
PeterPanettone 157 Posted 3 hours ago Another solution could be to subclass TRichEdit and then (temporarily) suppress the TAB character, but it's not worth the effort. Share this post Link to post