在Form放置一个ApplicationEvents控件, 在OnMessage事件中写下面的代码: const StdKeys = [VK_TAB, VK_RETURN]; { standard keys } ExtKeys = [VK_DELETE, VK_BACK, VK_LEFT, VK_RIGHT]; { extended keys } fExtended = $01000000; { extended key flag } begin Handled := False; with Msg do if ((Message >= WM_KEYFIRST) and (Message <= WM_KEYLAST)) and ((wParam in StdKeys) or {$IFDEF VER120}(GetKeyState(VK_CONTROL) < 0) or {$ENDIF} (wParam in ExtKeys) and ((lParam and fExtended) = fExtended)) then try if IsChild(WebPageControl1.ActivePage.Browser.Handle, hWnd) then { handles all browser related messages } begin with WebPageControl1.ActivePage.Browser.Application as IOleInPlaceActiveObject do Handled := TranslateAccelerator(Msg) = S_OK; if not Handled then begin Handled := True; TranslateMessage(Msg); DispatchMessage(Msg); end; end; except end;
mail.163.com
如果用ie打开,在用户名中输入字符后回车,登录邮箱按钮就被执行了。
我在窗体的FormKeyPress事件中,发现是#13后,webbrowser.setfocus,但仍然没有执行登录邮箱按钮操作,为什么?
在OnMessage事件中写下面的代码:
const
StdKeys = [VK_TAB, VK_RETURN]; { standard keys }
ExtKeys = [VK_DELETE, VK_BACK, VK_LEFT, VK_RIGHT]; { extended keys }
fExtended = $01000000; { extended key flag }
begin
Handled := False;
with Msg do
if ((Message >= WM_KEYFIRST) and (Message <= WM_KEYLAST)) and
((wParam in StdKeys) or {$IFDEF VER120}(GetKeyState(VK_CONTROL) < 0) or {$ENDIF}
(wParam in ExtKeys) and ((lParam and fExtended) = fExtended)) then
try
if IsChild(WebPageControl1.ActivePage.Browser.Handle, hWnd) then
{ handles all browser related messages }
begin
with WebPageControl1.ActivePage.Browser.Application as IOleInPlaceActiveObject do
Handled := TranslateAccelerator(Msg) = S_OK;
if not Handled then
begin
Handled := True;
TranslateMessage(Msg);
DispatchMessage(Msg);
end;
end;
except end;
1、uses ActiveX
2、WebPageControl1.ActivePage.Browser替换成你的WebBrowser