[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Handling onKeyDown event: some keys are not caught

Posted on 2005-04-29
10
Medium Priority
?
473 Views
Last Modified: 2012-06-21
Hi, all!

I need to watch some  pressed keys inside MovieClip loaded in "Flash Player" hosted inside Web browser (Internet Explorer or Netscape). I had created listener for onKeyDown event:

var oLst:Object = new Object();
oLst.onKeyDown = onKeyDown;
Key.addListener( oLst );
function onKeyDown()
{
      trace( "'" + Key.getCode() + "'" );
}.

Some keys are not caught by this one. For example, i need to process ESCAPE key, but this key is caught under Netscape and not caught under "Internet Explorer".

Why? And how to process ESCAPE in "Internet Explorer"?

The SWF used in Netscape and in IE is the same. And Action script is the same! I had moved event handler inside SWF instead of creating Java Script in HTML since onKeyDown event is not propagated to the HTML-elements when "Flash Player" has focus.

Thanks.


0
Comment
Question by:Alexey Fedorov
10 Comments
 
LVL 37

Expert Comment

by:CyanBlue
ID: 13899253
Howdy...  :)

I think that's happening because web browser is intercepting the specific key combinations before Flash does...  For example, if you press F1 key within the Flash movie inside of the web browser, Flash will never receive F1 key because the web browser takes it before Flash Player does...  
So, there is not a good work around for that...  You will need to stick to the common keys that web browser does not use...

That's my 2 cents...

CyanBlue
0
 
LVL 18

Expert Comment

by:Billystyx
ID: 13900216
Hving tried this too, I can confirm you just can't do anything with esc by itself.

Billystyx
0
 
LVL 3

Expert Comment

by:y_o_y
ID: 13906706
Hi,

why don't you trap the esc button first using javascript so that it would surely be caught in your swf.....

Y_o_Y
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:Alexey Fedorov
ID: 13919086
y_o_y, i tried this. When "Flash Viewer" has input focus, all keyboard input  is processed by "Flash Viewer".

I tried to install event handler isnside HTML:

document.onkeydown = onKeyDownPage;
window.onkeydown = onKeyDownPage; //--OR--
f.onkeydown = onKeyDownPage; //--OR--
//where f - is <object> tag for "Flash Viewer"

function onKeyDownPage( e )
{
  var ev = new InterEvent( e );
   alert( ev.code );
}

Under "Microsoft Internet Explorer" this handler works when "Flash" has no focus.

I need to intercept ESC keydown event when "Flash Player" has input focus, but this event for ESC is not visible in Flash's Action Script nor in HTML's Java Script.

I think, it is possible. In Netscape, ESC's keydownd event is intercepted by Flash.
0
 

Author Comment

by:Alexey Fedorov
ID: 13919428
Also, i want to notice, F1, for example, also is used by IE, but onkeydown event is working in both: in HTML, when the input focus is outside of Flash and in "Flash Viewer", when input focus is inside Flash.
Whenever F1 is pressed, regardless of  input focus location, it is always visible for:
  - Internet Explorer;
  - event handler (in Action Script or in HTML's Java Script, depending from input focus).

In case of ESC it is not. Why?
0
 
LVL 18

Accepted Solution

by:
Billystyx earned 750 total points
ID: 13919645
if you add this code to frame1 of a new fla:
myVar="nothing";
  if(Key.isDown(Key.ESCAPE)) {
  fscommand("trapallkeys", true);
    myVar="escape";
  }
and on frame2:
gotoAndPlay(1);

with a dynamic text field on stage, variable name myVar, then test the swf, leave flash and view your swf in the flash projector, it works.

Billystyx
0
 
LVL 18

Expert Comment

by:Billystyx
ID: 13919653
disregard the line:
fscommand("trapallkeys", true);
it doesn't need to be there.
Billystyx
0
 
LVL 18

Expert Comment

by:Billystyx
ID: 13966520
does this help?
It does work, just not in embedded flash in html (or your test window).
Only through the projector.
Billystyx
0
 

Author Comment

by:Alexey Fedorov
ID: 13975841
Yes, thanks Billystyx, it is a way: to check ESCAPE's state by means of "isDown" is the cycle. I had declined from this feature in my application and had leaved all as is: ESCAPE is detected in Netscape and not detected in Explorer. May be an undocumented way exists. Still, i decide do not use cycle inside Flash.
0
 
LVL 18

Expert Comment

by:Billystyx
ID: 13975886
you can use the same of course with the key listener - just wanted to point out it does work - in some situations:)

Good luck with your app!

billystyx
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Sometimes you know that one object has a specific child in it, but you can't find the child. This happened to me when I was trying to code some actionScript to make a toolbar work with its embedded buttons.  My partner had created the toolbar usi…
Recently, I was asked to recommend a tracking system to be implemented on a clients website. As the entire site was built on flash, my first thought was to suggest custom built tracking system. However, our company at that point of time didn't h…
The goal of the tutorial is to teach the user how to live broadcast using Flash Media Live Encoder and connecting it to YouTube to broadcast. Log into your Youtube account, choose live stream settings, start live stream from Flash Media Live Enc…
The goal of the tutorial is to teach the user how to select which audio input to use. Once you have an audio input plugged into the laptop or computer, you will go into the audio input settings and choose which audio input you want to use.
Suggested Courses

831 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