Insert/overwrite mode

  • In any program you may use the GetKeyState API function:

    if HiWord(GetKeyState(vk_Insert)) <> 0 then
    ShowMessage('Insert')
    else
    ShowMessage('Overwrite') ;

    The pressing of the Ins key can be caught when the program is idle:

    private
    procedure CheckKey(Sender: TObject; var Done: Boolean);

    procedure TForm1.FormCreate(Sender: TObject);
    begin
    Application.OnIdle := CheckKey;
    end;

    procedure TForm1.FormDestroy(Sender: TObject);
    begin
    Application.OnIdle := nil
    end;

    procedure TForm1.CheckKey(Sender: TObject; var Done: Boolean);
    begin
    if HiWord(GetKeyState(vk_Insert)) <> 0 then
    //whatever
    end;

    • Offizieller Beitrag
    Zitat

    In any program you may use the GetKeyState API function:

    Thank You. This is interesting.

    WPTools does it differently. It toggles the Inserting mode (property = same name) when VK_INSERT is pressed.

    Code
    procedure TWPCustomRtfEdit.KeyDown(var Key: Word; Shift: TShiftState);
    ...
    
    
    if not TextCursor.Inserting or not
                  (wpAlwaysInsert in EditOptions) then
                begin
                  TextCursor.Inserting := not TextCursor.Inserting;
                  DoUpdateEditState;
                end;