模拟按下键盘上的键随笔

procedure TForm1.Button1Click(Sender: TObject);

//模拟在edit1中按下字幕a键
begin

  PostMessage(Edit1.handle,wm_keydown,65,0);
end;

看完后,觉得这个模拟键挺不错的,结合可以完成一些自动的批量运算。

procedure TForm1.Button2Click(Sender: TObject);
begin
   edit1.SetFocus;
   edit1.Text:='hahah';
   postmessage(self.activecontrol.Handle,wm_char,vk_return,0);
end;

procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
   if key=#13 then
      Button1Click(Sender);
end;

原文地址:https://www.cnblogs.com/hqyj/p/2154141.html