Groups | Blog | Home
all groups > flash actionscript > december 2004 >

flash actionscript : key capture in full screen problems


Spam!?
12/7/2004 11:44:36 PM
Hi all, I don't know if this can actually be done, and I would rather know now
than when I have finished and the app doesn't work 100% perfectly...

I have an application that needs to be run from CD and be full screen and be
able to respond to EVERY key press possible!

I need to be able to capture every button on the keyboard (except perhaps the
power button and other "special ones" like I dunno if you can capture the print
screen button, I haven't been able to so far...) - whatever it needs to
perform such that any key press will produce a response (or do nothing
"obvious" with the app, as with the special keys), so I was mucking around with
some simple flash code and a base movie (attaching a listener.keyDown()) and it
all works fine EXCEPT for the following...

Neither ALT does nothing (well presumably it opens the menu as per normal
windows operation) (would like a key press please but not too bad if I can't
get it...)
F10 does nothing (presumably as above...?) (want a key press please?!?!)
ESC jumps out of full screen mode (don't want this to happen and would like a
keypress...)
Print Scn does nothing (well the cursor dissapears for a second - taking a
screen shot I assume - this I could live with)
Windows button does register as a key press (91 and/or 92) but opens the
"START" menu, I would preferr to be able to disable this but can live with it
if its too "naughty" to kill this "expected behaviour"...

can you SET Keys.getCode() = 0 to cancel a keypress?

By the way this was all done on a PC but I need it to behave the same (or as
close as possible) on the Mac...?
Spam!?
12/7/2004 11:49:49 PM
Spam!?
12/8/2004 12:21:00 AM
additional stuffing around has revealed that I CAN get the ESC and PRINT SCR
key codes to register if I put the listener on the "onKeyUp" (instead of
onKeyDown, which I was using), but this still doesn't help me to stop the ESC
key from "un-fullscreen-erising" my app...

I don't mind ALT-F4 or ALT-TAB working, I just don't want single key presses
to do "anything" (except what I tell them to in the code...)

Dunno if this clarifies anything but thought I would mention it...
NSurveyor
12/8/2004 12:41:30 AM
Alt problem: Key.isDown(18) - does not respond to onKeyUp or onKeyDown - try
putting in an onEnterFrame to check if pressed
F10 problem: Key.isDown(121) - does not respond to onKeyUp or onKeyDown - try
putting in an onEnterFrame to check if pressed
ESC problem: if(Key.getCode()==21){doSomething} - responds to onKeyUp and
onKeyDown - Don't know how to stop jumping out of full screen...
PrintScreen: one of those 'special keys' - it might be possible, I don't
know...

If I understand this correctly: 'SET Keys.getCode() = 0 to cancel a keypress',
you should store Key.getCode() in a variable, for isntance myCode =
Key.getCode(); Then to cancel myCode = 0; You can't set getCode() because it is
returning a value, so that wouldn't make sense (It's like saying Math.PI = 3:))
NSurveyor
12/8/2004 12:45:27 AM
If you use MX (aka Version 6) go to:
C:\Program Files\Macromedia\Flash MX\Help\Flash\html\24_appendix_c.html

And if you use MX2004 I think you would go to:
C:\Program Files\Macromedia\Flash MX2004\Help\Flash\html\24_appendix_c.html
Not sure though.

Or, go to Window > Using Flash. Then in the new window click on Using Flash
inside the Contents Tab. Then click on "Keyboard Keys and Key Code Values", and
look at the subsections. It explains all the keycodes supported by flash.
NSurveyor
12/8/2004 1:23:00 AM
Spam!?
12/8/2004 1:26:43 AM
NSurveyor, thanks for the heads up on teh "onEnterFrame" getting more info than
the "onKey*" events... cheers...

I seem to have confused you with my "can you SET getCode() to 0" - I don't
actually want that line of code to work, I want to know if there is a SETCODE
function (ie opposite to getCode), so that I can effectivly destroy the
"keypress" event...

Dunno if you know much about Javascript, but it would be kind of like
cancelBubble or in some other coding languages like "event.keyCode = 0".

Which effectively stops the key event from "going any further" - this is
related heavily to my "can you stop the ESC key from jumping out of full screen
mode - ie if you can cancel the keyPress then presumably the projector will not
get a "jump me out of full screen" mode request...

Clearer?

Thanks again for your onEnterFrame suggestion.
NSurveyor
12/8/2004 1:34:49 AM
Yes, it is clear. All you have to do is something like this:

delete(myListener.onKeyUp);
//or:
delete(myListener.onKeyDown);
//Replace myListener with the listener object or the movieclip you used to do
the
//onKeyUp, ex: if you did someListener.onKeyDown = function(){stuff}, then you
//would use delete(someListener.onKeyDown);

And if you are using Normal Mode for actionscripting (only available in MX2003
and lower, then the delete line will be said to have wrong syntax, but it is
correct.
NSurveyor
12/8/2004 1:41:40 AM
Or you can do this, if you prefer this method:

someListener.onKeyDown = 0;
//Just to keep it like other programming languages...
Spam!?
12/8/2004 10:53:00 PM
delete(myListener.onKeyUp);
//or:
delete(myListener.onKeyDown);
//Replace myListener with the listener object or the movieclip you used to do
the
//onKeyUp, ex: if you did someListener.onKeyDown = function(){stuff}, then you
//would use delete(someListener.onKeyDown);
//or
someListener.onKeyDown = 0;

I think (from what I have tested) what you are suggesting ONLY removes the
FUNCTION not the actual KEY CODE from the equation.

What I want to do is effectively remove the key press after I've handled it
myself - the reason I want to do this is so that I can stop the "START" button
showing the Windows Start Menu or stop the ESC key from "un-fullscreening" my
app... ie if the button is never pressed then it never gets "un-fullscreened",
or the ALT key making the "focus" switch to the projector menu...

From what I have read this is probably not possible, I'm just after some
confirmation or denial, as to whether I am wasting my time developing this app
in Flash, or if I should look at Director or another programming solution.

The Javascript below is the concept that I am working from... and might clear
things up more...

//inside an "onKeyDown" event for example
alert ("this is the key that was pressed: " + event.keyCode);
event.returnValue = false; //this effectively denies that the event ever
happened

This is a way of doing it in visual basic...

'inside a KeyDown event you are given KeyCode and Shift parameters
Call MsgBox("this is the key that was pressed: " & KeyCode)
KeyCode = 0 ' this will effectively say that NO key was pressed.

So there you go.
Since the Key object in Flash only provides (what appears to me) to be read
only functions then I'm guessing that you can't do what I want to do in
flash... PLEASE correct me if I am wrong!!!

However if you CAN do it in another application such as Director, PLEASE
PLEASE PLEASE let me know!!! I would rather have a Mac/PC solution than writing
something only for PC, but also the frame work of Flash/Director suits my
purposes because the app is Graphics and Sound oriented, so it makes sense to
work with these tools...

Any ideas...?


NSurveyor
12/8/2004 10:59:08 PM
Flash cannot 'cancel' keypresses. You're going to have to look into something
else. I think they made it that way, because it would be a security issue.

Imagine you just downloaded an exe file. You open it up, it opens in full
screen. And you see there is no close button. Then you try the Escape key and
all the other button combos to shut down the app - oh no! Someone is canceling
the keypresses! Now, you have to 'flip the switch on your computer' :(

I don't know much about Director, try posting in the Director Forums, and see
if it is possible.
Spam!?
12/8/2004 11:06:15 PM
Yeah, I know what you mean about the security issues...

I don't really want to cancel key presses - like if someone pressed ALT+TAB or
ALT+F4 then thats fine (a combination of keys) but I just want to use some of
the single keys that Flash already has (F10, ESC and Windows Key) to do other
things AND NOT what they are supposed to... but its probably not possible as
you say.

BTW, Just for info - even with onEnterFrame I couldn't get F10 to
register...?!?!

I will do as you say and post in Director forum... thnx for ur help!
:D
CI2
1/13/2005 2:08:04 PM
I think F10 is used by Flash player internally... I am looking for a way to
capture it as well. All other Function keys seem to work, but I had to issue
an fscommand('trapallkeys','true'); which tells Flash Player to pass all
keystrokes to the app (except apparently F10...).
Spam!?
1/16/2005 11:42:34 PM
You can capture F10 but ONLY in a PROJECTOR... I think... I have done it... so
I think that its got something to do with that BUT ALSO you can't (maybe, I
haven't done that much experimentation) get it with a "Key Listener".

But I have resorted to using "onEnterFrame" which can pretty much "GET"
anything (in a projector with no menu), if you just test "Key.IsDown(121)"...

The only problem I have found is that if you "tap" the key, it may not
register in the "onEnterFrame" since the tap may occur between frames (so to
speak).

I tried upping the frame rate to 24 and 36, but it doesn't seem to make any
difference...
Spam!?
1/16/2005 11:50:27 PM
Just to clarify...

You can get just about any keypress (even though it may still perform its
regular operation also) in a projector (eg: Windows Keys)
By using something like this:
for (var i = 1; i<255;I++) {
if ( Key.IsDown(i) ) {
trace('The key just pressed was associated with the CODE :' + i );
}
}

Hope this helps...

F10 is the short cut (I think) to the "menu" - if you run a SWF and press F10
then the menu highlights... I think... my brain is fuzzing out so some of this
might be rubbish...
NSurveyor
1/17/2005 12:13:27 AM
Spam!?
1/17/2005 12:17:29 AM
I thought I read somewhere that setInterval was tied to the frame rate so that
if your setInterval was less than your frame rate it would still only fire a
set interval as quickly as your frame rate allowed...

Please correct me if I'm wrong...
Spam!?
1/17/2005 12:51:17 AM
Hmm... you are right... the interval does fire at less than the frame rate...

Cool... so... is there a sweet spot for "intervals"?

I imagine that setting the interval to 1 would be next to impossible for any
computer less powerful than a liquid nitrogen cooled supercomputer to keep up
with so for "key press" captures is there going to be a good number, or am I
just going to have to experiment?
Spam!?
1/17/2005 1:12:24 AM
Well just from a quick test with interval set to 1 I can still press a key fast enough for it not to register...
:(
:(
Spam!?
1/17/2005 1:21:21 AM
Slightly related but a little off topic:
Has anyone else noticed that some keyboards (I think its the keyboard...)
registers *two key codes* when some keys are pressed...

It depends which machine I am testing on but with one keyboard I get - for
just an example - a 16 and a 160 when I press the left shift and a 16 and a 161
when I press the right shift button... similar behaviour on other "left/right"
buttons ctrl/alt, etc...

I just thought its a bit weird... so letting you know...
Jeckyl
1/17/2005 11:37:00 AM
[quoted text, click to view]

you are wrong :):)

setInterval can first more or less often than the frame rate. HOWEVER, it
does NOT fire reliably at the rate you enter. How often it does fire in
reality depends on the frame rate. Quite often it will at a longer interval
than what you nominate. Its not first at the frame rate, or at the interval
you nominate, but some where between the interval you nominate and about
double that (depending on the exact combination of interval and frame rate
you use .. there seems to be no logic to it).

Its ok as long as you don't rely on setInterval firing at anywhere near the
rate you nominate. Or if you do need exact timing, then use getTimer along
with setInterval to work our exact difference (in milliseconds) between
firings and adjust calculation etc wrt that.
--
All the best,
Jeckyl

Jeckyl
1/17/2005 11:53:26 AM
It all depends on how fast you think someone can press a key, and how
quickly you need to respond when they do.
--
All the best,
Jeckyl

AddThis Social Bookmark Button