WMPeters
asked on
Getting keys to work in WebBrowser
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 ?
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 ?
ASKER
Markus, i get the following error :
[Error] Unit1.pas(46): Undeclared identifier: 'CoInitialize'
[Error] Unit1.pas(49): Undeclared identifier: 'CoUnitialize'
Some unit i forgot ?
[Error] Unit1.pas(46): Undeclared identifier: 'CoInitialize'
[Error] Unit1.pas(49): Undeclared identifier: 'CoUnitialize'
Some unit i forgot ?
> Some unit i forgot ?
Yep, my fault, sorry.
You have to include ActiveX -> uses ActiveX ;-)
Markus
Yep, my fault, sorry.
You have to include ActiveX -> uses ActiveX ;-)
Markus
ASKER
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:/P acMan.Swf' );
end;
Initialization
CoInitialize(nil);
Finalization
CoUninitialize;
end.
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:
begin
application.Terminate;
end;
procedure TForm1.Pacman1Click(Sender
begin
wb1.navigate('file:///c:/P
end;
Initialization
CoInitialize(nil);
Finalization
CoUninitialize;
end.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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:/P acMan.Swf' );
end;
Initialization
CoInitialize(nil);
Finalization
CoUninitialize;
end.
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:
begin
application.Terminate;
end;
procedure TForm1.Pacman1Click(Sender
begin
wb1.navigate('file:///c:/P
end;
Initialization
CoInitialize(nil);
Finalization
CoUninitialize;
end.
ASKER
Works fine, now hopefully i can get other keys to work for other games.
Add this to your unit:
initialization
CoInitialize(nil);
finalization
CoUninitialize;
Markus