你参考下如下代码:<br><br>procedure TForm1.SendKeys(sSend:string);<br>var<br> i:integer;<br> Sstr:string;<br> focushld,windowhld:hwnd;<br> threadld:dword;<br> ch: byte;<br>begin<br> windowhld:=GetForegroundWindow;<br> threadld:=GetWindowThreadProcessId(Windowhld,nil);<br> AttachThreadInput(GetCurrentThreadId,threadld,true);<br> Focushld:=getfocus;<br> getcursorpos(p); //查鼠标坐标<br> Focushld:=WindowFromPoint(p); //返回句柄<br> AttachThreadInput(GetCurrentThreadId,threadld,false);<br> if (focushld=0) or<br> (focushld=Self.Memo1.Handle) or<br> (focushld=Self.Edit1.Handle) or<br> (focushld=Self.Edit2.Handle) or<br> (focushld=SpinEdit1.Handle) then<br> begin<br> Exit;<br> end;<br> i := 1;<br> while i &lt;= Length(sSend) do<br> begin<br> ch := byte(sSend);<br> if Windows.IsDBCSLeadByte(ch) then<br> begin<br> Inc(i);<br> SendMessage(focushld, WM_IME_CHAR, MakeWord(byte(sSend), ch), 0);<br> end<br> else<br> begin<br> SendMessage(focushld, WM_IME_CHAR, word(ch), 0);<br> end;<br> Inc(i);<br> end;<br> SendMessage(focushld, WM_IME_CHAR, word(13), 0);<br>end;<br><br>//定时器定时发送字符<br>procedure TForm1.Timer1Timer(Sender: TObject);<br>begin<br> SendKeys('ABCD1234大话西游');<br>end;<br>