Board index » delphi » Hotkey for inserting frequently used text

Hotkey for inserting frequently used text

Hello

How can i manage to put some frequently used text in a control by pressing a
hotkey ?
for example: the current active control is a TEdit and by pressing ALT-A i
want to place the text 'Any text' in that TEdit .

Can't figure this one out! Got some hotkeys but they don't refer to the
control that was active on the moment the hotkey was pressed...

Thanx in advance

Roel

 

Re:Hotkey for inserting frequently used text


Quote
In article <9ui6oo$hj...@news1.xs4all.nl>, "RS" <tendern...@home.nl> writes:
>for example: the current active control is a TEdit and by pressing ALT-A i
>want to place the text 'Any text' in that TEdit .

>Can't figure this one out! Got some hotkeys but they don't refer to the
>control that was active on the moment the hotkey was pressed...

Use the following in the OnKeyUp of a TEdit. OnKeyUp so that repeating keys
will not cause multiple entries, and because OnKeyPress does not receive the
Alt key...

procedure TForm1.Edit1KeyUp(Sender: TObject; var Key: Word;
                            Shift: TShiftState);
const
  VK_A = 65;  // word value for 'A' key, not declared by Delphi
begin
  if (Key = VK_A) and (Shift = [ssAlt]) then begin
    with TEdit(Sender) do begin
      Text := 'Any text';
      {select text}
      SelStart := 0;
      SelLength := Length(Text);
    end; {with TEdit(Sender)}
    Key := 0; // kill 'a' character so that it is not entered as well as the
text
  end; {if (Key = VK_A) and (Shift = [ssAlt])}
end;

Alan Lloyd
alangll...@aol.com

Re:Hotkey for inserting frequently used text


Quote
"RS" <tendern...@home.nl> wrote in message

news:9ui6oo$hja$1@news1.xs4all.nl...

Quote
> Hello

> How can i manage to put some frequently used text in a control by pressing
a
> hotkey ?
> for example: the current active control is a TEdit and by pressing ALT-A i
> want to place the text 'Any text' in that TEdit .

> Can't figure this one out! Got some hotkeys but they don't refer to the
> control that was active on the moment the hotkey was pressed...

The form's ActiveControl is the control that currently has the focus. When
the hotkey is pressed do the following:

if ActiveControl is tCustomEdit
then tCustomEdit (ActiveControl).SelText := theTextToInsert;

Other Threads