Mega Code Archive

 
Categories / Delphi / VCL
 

Intercepting the ctrl-v key in a tmemo

Question: How can I intercept the Ctrl-V key in a TMemo component and paste custom text that is not currently on the clipboard? Answer: The following example demonstrates trapping the Ctrl-V key in a TMemo component. Example: uses ClipBrd; procedure TForm1.Memo1KeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); begin if ((Key = ord('V')) and (ssCtrl in Shift)) then begin if Clipboard.HasFormat(CF_TEXT) then ClipBoard.Clear; Memo1.SelText := 'Delphi is RAD!'; key := 0; end; end;