[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details

Capture keys from TWebBrowser

Asked by feaci in Delphi Programming, Delphi Components

Tags: Delphi

Delphi 6 in Windows Xp.
I have a TWebBrowser control in a form, and I would like to get the keys pressed when the focus in on the TWebBrowser (for example: control keys, or ESC key, or other keys).

I tried to use KeyPreview in association with OnKey*** events, unsuccesfully.
I tried to put an event handler in my form (as I read in many places, for example http://www.experts-exchange.com/Programming/Languages/Pascal/Delphi/Q_10225776.html), unsuccessfully (see code in code section).

Can you help me, please?
Many thanks in advance.
Federico.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
This is the message handler code I added to my form:
 
Tdlg_DOC_edit = class(TForm)
 ...
   wb: TWebBrowser;
   FOleInPlaceActiveObject: IOleInPlaceActiveObject;
   SaveMessageHandler: TMessageEvent;
   procedure message_handler(var Msg: TMsg; var Handled: Boolean);
end;
 
procedure Tdlg_DOC_edit.FormCreate(Sender: TObject);
begin
   SaveMessagehandler := Application.OnMessage;
   Application.OnMessage := message_handler
end;
 
procedure Tdlg_DOC_edit.message_handler(var Msg : TMsg;var Handled : Boolean);
const STANDARD_KEYS = [VK_BACK, VK_UP, VK_DOWN, VK_LEFT, VK_RIGHT];
var
 iOIPAO : IOleInPlaceActiveObject;
 Dispatch : IDispatch;
begin
// exit if we don't get back a webbrowser object
 if (wb = NIL) then begin Handled := False;Exit end;  
 
 Handled := IsDialogMessage(wb.Handle, Msg);
 if Handled AND NOT wb.Busy then begin
  if (FOleInPlaceActiveObject = NIL) then begin
   Dispatch := wb.Application;
   if (Dispatch <> NIL) then begin
    Dispatch.QueryInterface(IOleInPlaceActiveObject, iOIPAO);
    if (iOIPAO <> NIL) then FOleInPlaceActiveObject := iOIPAO
   end
  end;
 
  if (FOleInPlaceActiveObject <> NIL) then
   if ((Msg.message = WM_KEYDOWN) OR (Msg.message = WM_KEYUP)) AND
    (Msg.wParam in STANDARD_KEYS)
   then //nothing - do not pass on Backspace, Left or Right arrows
   else FOleInPlaceActiveObject.TranslateAccelerator(Msg)
 end
end;
 
initialization
   OleInitialize(NIL)
finalization
   OleUnInitialize
end.
[+][-]04/25/09 09:36 AM, ID: 24232637Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04/27/09 01:26 AM, ID: 24239725Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04/27/09 09:55 PM, ID: 24247715Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08/17/09 02:27 PM, ID: 25118548Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091021-EE-VQP-81 - Hierarchy / EE_QW_3_20080625