?
Solved

Getting keys to work in WebBrowser

Posted on 2003-03-01
7
Medium Priority
?
177 Views
Last Modified: 2010-04-04
Hi there,

I'm making a little program for playing flash games without a internet connection, it's ment for my coworkers when they want to play a little game when they have nothing to do, without having to go on internet.

The games are flashgames (like pacman andso), which i download from internet.

I use the WebBrowser component to navigate to the <filename>.swf file, and that works okay.

But then, after you click <PLAY>, the game starts, pacman (in this example) starts eating his way, but you can't send him in any direction...bummer...

I tried to made the WebBrowser component the active one the form, but no luck.
Even when I first click in the browser component, no luck.

In IE6 it's works fine with just the <filename>.swf file, but as soon as mine program starts, it doesn't work in my program.

It's very simpel for now, just a form, a menu bar with a start option and a webbrowser component. But before i go making the program be able to play more games, update itself etc., i first want to get this problem fixed.

For the moment i'm talking about the cursor keys, but ofcourse al keys have to go directly to the webbrowser component.

What am i doing wrong ?
0
Comment
Question by:WMPeters
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 6

Expert Comment

by:DaFox
ID: 8047590
Hi.

Add this to your unit:

initialization
  CoInitialize(nil);

finalization
  CoUninitialize;

Markus
0
 

Author Comment

by:WMPeters
ID: 8047664
Markus, i get the following error :

[Error] Unit1.pas(46): Undeclared identifier: 'CoInitialize'
[Error] Unit1.pas(49): Undeclared identifier: 'CoUnitialize'

Some unit i forgot ?
0
 
LVL 6

Expert Comment

by:DaFox
ID: 8047729
> Some unit i forgot ?

Yep, my fault, sorry.
You have to include ActiveX -> uses ActiveX ;-)

Markus
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:WMPeters
ID: 8047739
Yep, i found that unit, but still doesn't work.

The code now looks like this: (still dirty)
Any ideas?

---

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Menus, OleCtrls, SHDocVw, ComCtrls, activex;

type
  TForm1 = class(TForm)
    MainMenu1: TMainMenu;
    File1: TMenuItem;
    Close1: TMenuItem;
    StatusBar1: TStatusBar;
    wb1: TWebBrowser;
    Pacman1: TMenuItem;
    procedure Close1Click(Sender: TObject);
    procedure Pacman1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}


procedure TForm1.Close1Click(Sender: TObject);
begin
application.Terminate;
end;

procedure TForm1.Pacman1Click(Sender: TObject);
begin
  wb1.navigate('file:///c:/PacMan.Swf');
end;

Initialization
 CoInitialize(nil);


Finalization
 CoUninitialize;

end.
0
 
LVL 6

Accepted Solution

by:
DaFox earned 300 total points
ID: 8047799
Okaydokay...

Now we got 2 possibilities:

1. We set up our own message handler:
...
  private
    FOleInPlaceActiveObject: IOleInPlaceActiveObject;
    procedure MyMessageHandler(var Msg: TMsg; var Handled: Boolean);

...

procedure TForm1.MyMessageHandler(var Msg: TMsg; var Handled: Boolean);
var
  iOIPAO: IOleInPlaceActiveObject;
  Dispatch: IDispatch;
begin
  // exit if we don't get back a webbrowser object
  if (WebBrowser1 = nil) then
  begin
    Handled := false;
    exit;
  end;

  Handled := (IsDialogMessage(WebBrowser1.Handle, Msg) = True);

  if (Handled) and (not WebBrowser1.Busy) then
  begin
    if FOleInPlaceActiveObject = nil then
    begin
      Dispatch := WebBrowser1.Application;
      if Dispatch <> nil then
      begin
        Dispatch.QueryInterface(IOleInPlaceActiveObject, iOIPAO);
        if iOIPAO <> nil then FOleInPlaceActiveObject := iOIPAO;
      end;
    end;
    if FOleInPlaceActiveObject <> nil then
    begin
      if ((Msg.message = WM_KEYDOWN) or (Msg.message = WM_KEYUP)) and ((Msg.wParam = VK_BACK) or (Msg.wParam = VK_LEFT) or (Msg.wParam = VK_RIGHT)) then
        //nothing - do not pass on Backspace, Left or Right arrows
      else
         FOleInPlaceActiveObject.TranslateAccelerator(Msg);
    end;
  end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Application.OnMessage := MyMessageHandler;
end;

2. -> http://community.borland.com/article/0,1410,6302,00.html (if we don't succeed using possibility 1 ;-)

Markus
0
 

Author Comment

by:WMPeters
ID: 8047814
Yep, i found that unit, but still doesn't work.

The code now looks like this: (still dirty)
Any ideas?

---

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Menus, OleCtrls, SHDocVw, ComCtrls, activex;

type
  TForm1 = class(TForm)
    MainMenu1: TMainMenu;
    File1: TMenuItem;
    Close1: TMenuItem;
    StatusBar1: TStatusBar;
    wb1: TWebBrowser;
    Pacman1: TMenuItem;
    procedure Close1Click(Sender: TObject);
    procedure Pacman1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}


procedure TForm1.Close1Click(Sender: TObject);
begin
application.Terminate;
end;

procedure TForm1.Pacman1Click(Sender: TObject);
begin
  wb1.navigate('file:///c:/PacMan.Swf');
end;

Initialization
 CoInitialize(nil);


Finalization
 CoUninitialize;

end.
0
 

Author Comment

by:WMPeters
ID: 8047825
Works fine, now hopefully i can get other keys to work for other games.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question