下面函数用于模拟VB里面的sendkey函数,可以向当前有焦点的输入<br>procedure SendKeys(Mstr:string);<br>var CharCode,i:integer;<br> Sstr:string;<br> focushld,windowhld:hwnd;<br> threadld:dword;<br>begin<br> windowhld:=GetForegroundWindow;<br> threadld:=GetWindowThreadProcessId(Windowhld,nil);<br> AttachThreadInput(GetCurrentThreadId,threadld,true);<br> Focushld:=getfocus;<br> AttachThreadInput(GetCurrentThreadId,threadld,false);<br> if focushld<>0 then<br> begin<br> for i:=1 to length(Mstr) do<br> begin<br> Sstr:=Mstr;<br> CharCode:=ord(Sstr[1]);<br> if length(Sstr)>1 then<br> CharCode:=CharCode shl 8+ord(Sstr[2]);<br> sendmessage(Focushld,WM_IME_CHAR,CharCode,1);<br> end;<br> end;<br>end;<br><br>