T
turbozzh
Unregistered / Unconfirmed
GUEST, unregistred user!
使用热键向IE窗口中的Input(Text类型)发出KeyDown或者KeyUp事件,只能响应回车键,其他一律不响应,是何原因?<br>代码如下:<br>unit FormMain;<br>interface<br>uses<br> Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br>Dialogs, StdCtrls;<br><br>type<br> TForm1 = class(TForm)<br> procedure FormCreate(Sender: TObject);<br> procedure FormDestroy(Sender: TObject);<br> procedure FormShow(Sender: TObject);<br> private<br> { Private declarations }<br> Atom1,Atom2:Atom;<br> procedure hotkey(var msg:tmessage);message wm_hotkey;//响应热键消息<br> public<br> { Public declarations }<br> end;<br><br>var<br> Form1: TForm1;<br><br>implementation<br>{$R *.dfm}<br><br><br>procedure TForm1.FormCreate(Sender: TObject);//注册两个热键<br>begin<br> Atom1:=globaladdatom('hot key');<br> Atom2:=globaladdatom('hot key');<br> RegisterHotKey(handle,Atom1,MOD_ALT,VK_f12);<br> RegisterHotKey(handle,Atom2,MOD_ALT,VK_F11);<br> Form1.Top:=0;<br>end;<br><br><br>procedure TForm1.FormDestroy(Sender: TObject);//销毁热键注册<br>begin<br> GlobalDeleteatom(Atom1);<br> GlobalDeleteatom(Atom2);<br>end;<br><br>procedure TForm1.hotkey(var msg:tmessage); ;//响应热键消息<br>var<br> Handles:HWND;<br> 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> <br> <br>