procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if (ssCtrl in Shift) and ((Key = ord('s')) or (Key = ord('S'))) then
SetWindowText(Edit1.Handle, PChar('大家好'));
end;
不过,“光标所在的位置”的句柄我也不知道如何获得
procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if (ssCtrl in Shift) and ((Key = ord('s')) or (Key = ord('S'))) then
begin
Clipboard.Astext:='大家好';
SendMessage(getfocus(),WM_paste,0,0);
end;
end;
完整、完美答案:
form的keypreview设为true
procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if (ssCtrl in Shift) and ((Key = ord('s')) or (Key = ord('S'))) then
SetWindowText(getfocus(), PChar('大家好'));
end;