What I'm trying to accomplish:
I'm using this code [KeyPreview is True]:
procedure TFMsg.FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
begin
if (Shift = [ssCtrl]) and (Key = $0D) then
begin
Key := 0;
btnSendClick(Sender); //this moves the text and empties the TMemo box
end;
end;
What's actually happening:
Any help gratefully received. Thank you!
The best way to handle this is as follows:
Note that you don't need to attach the action to anything. It's mere presence is enough to ensure that the shortcut will be handled.
For compound keyboard actions using modifier keys it's always simplest to use an action shortcut and so keep at arm's length from the lower level keyboard handling code.
Your action handler might look like this:
if ActiveControl is TMemo then
begin
Memo := TMemo(ActiveControl);
Text := Memo.Text;
Memo.Clear;
SelectNext(Memo, True, True);
if ActiveControl is TMemo then
begin
Memo := TMemo(ActiveControl);
Memo.Text := Text;
end;
end;
In this code I'm assuming that there are multiple memos and the text is moved from one memo to the next one in the tab order. But your needs may well differ. In which case I'm sure it will be obvious what you need to do for your scenario.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With