模拟键盘输入
var
s:string;
f1,f2,f3,sl:longint;
begin
S:= '你要输出的字';
//--得到当前焦点控减句柄发消息
f1:=GetForegroundWindow;
f2:=GetWindowThreadProcessId(f1,nil);
AttachThreadInput(GetCurrentThreadId,f2,true);
f3:=getfocus;
AttachThreadInput(GetCurrentThreadId,f3,false);
//--没焦点就退出
if f3 = 0 then Exit;
//--模拟键盘输入
sl:=1;
while sl<>length(s)+1 do
begin
if ord(s[sl])<130 then
begin
SendMessage(f3, $0286,ord(s[sl]),0);
sl:=sl+1;
end
else
begin
SendMessage(f3, $0286,(ord(S[sl]) shl 8)+ord(S[sl+1]),0);
sl:=sl+2;
end;
end;
//模拟完毕
result:=s;
end;
用随机数就OK了