给你一个简单的例子:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ExtCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
Timer1: TTimer;
procedure Button1Click(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure FormActivate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.Button1Click(Sender: TObject);
begin
form1.Timer1.Enabled:=true;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
keybd_event( byte('A'), MapVirtualKey( byte('A'), 0 ), 0 , 0 ); // 'A' down
keybd_event( byte('A'), MapVirtualKey( byte('A'), 0 ), KEYEVENTF_KEYUP , 0 ); // 'A' up
end;
procedure TForm1.FormActivate(Sender: TObject);
begin
form1.Timer1.Enabled:=false;
end;
end.
按下BUTTON1 后,你可以把键盘焦点置于任何一个需要键盘输入的应用程序窗体上,就可以看到结果了,鼠标输入同此理.