Alexey Fedorov
asked on
Handling onKeyDown event: some keys are not caught
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.
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.
Hving tried this too, I can confirm you just can't do anything with esc by itself.
Billystyx
Billystyx
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
why don't you trap the esc button first using javascript so that it would surely be caught in your swf.....
Y_o_Y
ASKER
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.
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.
ASKER
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?
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?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
disregard the line:
fscommand("trapallkeys", true);
it doesn't need to be there.
Billystyx
fscommand("trapallkeys", true);
it doesn't need to be there.
Billystyx
does this help?
It does work, just not in embedded flash in html (or your test window).
Only through the projector.
Billystyx
It does work, just not in embedded flash in html (or your test window).
Only through the projector.
Billystyx
ASKER
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.
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
Good luck with your app!
billystyx
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