为什么发消息给IE的Input(text)对象不能完全响应?(100分)

  • 主题发起人 主题发起人 turbozzh
  • 开始时间 开始时间
T

turbozzh

Unregistered / Unconfirmed
GUEST, unregistred user!
使用热键向IE窗口中的Input(Text类型)发出KeyDown或者KeyUp事件,只能响应回车键,其他一律不响应,是何原因?<br>代码如下:<br>unit FormMain;<br>interface<br>uses<br>&nbsp; Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br>Dialogs, StdCtrls;<br><br>type<br>&nbsp;TForm1 = class(TForm)<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;procedure FormCreate(Sender: TObject);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;procedure FormDestroy(Sender: TObject);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;procedure FormShow(Sender: TObject);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; private<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; { Private declarations }<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Atom1,Atom2:Atom;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;procedure hotkey(var msg:tmessage);message wm_hotkey;//响应热键消息<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; public<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; { Public declarations }<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end;<br><br>var<br>&nbsp; Form1: TForm1;<br><br>implementation<br>{$R *.dfm}<br><br><br>procedure TForm1.FormCreate(Sender: TObject);//注册两个热键<br>begin<br>&nbsp;Atom1:=globaladdatom('hot key');<br>&nbsp;Atom2:=globaladdatom('hot key');<br>&nbsp;RegisterHotKey(handle,Atom1,MOD_ALT,VK_f12);<br>&nbsp;RegisterHotKey(handle,Atom2,MOD_ALT,VK_F11);<br>&nbsp;Form1.Top:=0;<br>end;<br><br><br>procedure TForm1.FormDestroy(Sender: TObject);//销毁热键注册<br>begin<br>&nbsp;GlobalDeleteatom(Atom1);<br>&nbsp;GlobalDeleteatom(Atom2);<br>end;<br><br>procedure TForm1.hotkey(var msg:tmessage); ;//响应热键消息<br>var<br>&nbsp;Handles:HWND;<br>&nbsp;lpPoint:TPoint;<br>begin<br>if (msg.LParamHi=VK_F12) and (msg.LParamLo=MOD_ALT) then<br>Begin<br>If Not Form1.Visible Then<br>Form1.Visible:=True;<br>SetForegroundWindow(handle);//显示并提前窗口<br>End;<br>if (msg.LParamHi=VK_F11) and (msg.LParamLo=MOD_ALT) then<br>Begin<br>GetCursorPos(lpPoint);//得到鼠标位置,运行是处于IE中Input(Text类型)上<br>MyHandle:=WindowFromPoint(lpPoint);//得到此Input(Text类型)的句柄<br><br>PostMessage(MyHandle,WM_KeyUp,Ord('1'),0);//发送字符"1"<br>//奇怪,这句IE中的Input(Text)不响应<br>PostMessage(MyHandle,WM_KEYDown,13,0);//发送回车键<br>//可以响应回车键<br>End<br>end;<br>End.<br>&nbsp;<br>&nbsp;<br>
 
后退
顶部