如何向浏览器(IE)输入栏发送中文字符?100分!(100分)

  • 主题发起人 kingkong
  • 开始时间
K

kingkong

Unregistered / Unconfirmed
GUEST, unregistred user!
最近做了聊天室攻击程序(只做研究,不搞破坏),其中的核心函数是取
得当前鼠标下的窗口句柄后向该窗口中拥有焦点的输入栏发送中文或
西文字符,在写字板等软件下发送中文或西文均正常,但向IE5.0中的
输入栏发送西文正常而中文却出现乱码,怎么解决?废话少说,不欢迎灌水!
请发修改后的源程序,本人调试成功后立即给分!!!!!!!

//模拟按键函数
procedure TForm1.SendKeys(sSend:string);
var
i:integer;
Sstr:string;
focushld,windowhld:hwnd;
threadld:dword;
ch: byte;
begin
windowhld:=GetForegroundWindow;
threadld:=GetWindowThreadProcessId(Windowhld,nil);
AttachThreadInput(GetCurrentThreadId,threadld,true);
Focushld:=getfocus;
getcursorpos(p)
//查鼠标坐标
Focushld:=WindowFromPoint(p)
//返回句柄
AttachThreadInput(GetCurrentThreadId,threadld,false);
if (focushld=0) or
(focushld=Self.Memo1.Handle) or
(focushld=Self.Edit1.Handle) or
(focushld=Self.Edit2.Handle) or
(focushld=SpinEdit1.Handle) then
begin
Exit;
end;
i := 1;
while i <= Length(sSend) do
begin
ch := byte(sSend);
if Windows.IsDBCSLeadByte(ch) then
begin
Inc(i);
SendMessage(focushld, WM_IME_CHAR, MakeWord(byte(sSend), ch), 0);
end
else
begin
SendMessage(focushld, WM_IME_CHAR, word(ch), 0);
end;
Inc(i);
end;
SendMessage(focushld, WM_IME_CHAR, word(13), 0);
end;

//定时器定时发送字符
procedure TForm1.Timer1Timer(Sender: TObject);
begin
SendKeys('ABCD1234大话西游');
end;
 
我在IE6实验你的程序正常,哎,可惜阿,100分。
另外,delphi光盘上有一个sndkey32.pas,
将其copy到你的程序use它,
里面有一个sendkeys()函数可以向当前拥有焦点的窗体发送按键,
我一直用它从来没出过差错。
你也可以用发送wm_paste来增加文本。
 
对不起,我用的是Win98加IE5.0,确实是发送汉字出现乱码,是不是汉字编码不对,
请祥细指点,成功后一定给分;另外,delphi光盘上有一个sndkey32.pas好象不能发
送汉字;
 
sorry,sndkey32应该是不能发送汉字,我没有IE5所以不能帮你测试了。
不过应该不是编码的问题因为在写字板等软件下发送中文或西文均正常,
你可以换一个思路。剪贴版是肯定没有编码问题的。
procedure TForm1.Timer1Timer(Sender: TObject);
var
p:TPoint;
handle:THandle;
begin
GetCursorPos(p);
handle:=WindowFromPoint(p);
PostMessage(handle,WM_Paste,0,0);
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
Memo1.SetFocus;
Memo1.SelectAll;
SendMessage(Memo1.handle,WM_Copy,0,0);
end;
当然你也可以用发送WM_SetText消息
 
剪贴版发送WM_Paste消息至写字板等软件下的确可以,但发送至IE输入栏却没有反应,
原来模拟按键的方法中文至少还有乱码,现在连原来的乱码都没有,甚至连
西文都无法发送,不知您试过没有。
 
可以直接用SendMessage向IE的地址栏发字符串的.只是现在我无法测试.
 
我在IE6,英文XP中测试,只要是输入法处于EN状态,中文就乱码,处于CH状态,
就可以取得正常结果
这与我以前做输入法遇到的问题是一样的,在发送之前,要先将目标设为CH状态:
if not immisime($0000804) then
postmessage(houtput,WM_INPUTLANGCHANGEREQUEST,0,$00000804);
 
xiao_min:
Thanks!Here you are.........
 
多人接受答案了。
 
外挂式输入法初步实现 http://www.2ccc.com/article.asp?articleid=942
 
顶部