Board index » delphi » Insert Hotkey

Insert Hotkey

Hi..sorry to post again within such a short time..

Anyone know what code is needed to make the Insert key on a standard
keyboard toggle a TMemo component text input between Insert and
Overwrite? At the moment the only option that TMemo allows is Insert,
and I would like to know first how to check for the key press and then
what code is necessary to actually perform the desired action (i.e
Insert or Overwrite).
        Thanks,
        Nicholas

 

Re:Insert Hotkey


Quote
> Anyone know what code is needed to make the Insert key on a standard
> keyboard toggle a TMemo component text input between Insert and
> Overwrite? At the moment the only option that TMemo allows is Insert,
> and I would like to know first how to check for the key press and then
> what code is necessary to actually perform the desired action (i.e
> Insert or Overwrite).

Nicholas,

you may be shocked to know that the standard Windows multiline edit control
(aka TMemo) only supports insert mode. To get it to do overtype attach this
handler to the OnKeyPress event of the memo:

procedure TScratchMain.Memo1KeyPress(Sender: TObject; var Key: Char);
begin
  If (Sender Is TCustomEdit) and Odd(GetKeyState(VK_INSERT)) Then
  With TCustomEdit(Sender) Do
    If SelLength = 0 Then
    Case Key of
      ' '..#126, #128..#255: Begin
          SelLength := 1;
          If (SelLength > 0) and (SelText[1] = #13) Then
            SelLength := 2;
        End;
    End;
end;

With this handler the control will start out in insert mode since the state
of VK_INSERT is not toggled by default. Pressing it once will toggle the
key and put the control in overtype mode. If you want it to start out in
overtype, use "not Odd(...)" in the If statement.

Peter Below (TeamB)  100113.1...@compuserve.com)

Other Threads