View comments | RSS feed

Key


Object
    |
    +-Key

public class Key
extends Object

The Key class is a top-level class whose methods and properties you can use without a constructor. Use the methods of the Key class to build an interface that can be controlled by a user with a standard keyboard. The properties of the Key class are constants representing the keys most commonly used to control applications, such as Arrow keys, Page Up, and Page Down.

A Flash application can only monitor keyboard events that occur within its focus. A Flash application cannot detect keyboard events in another application.

Availability: ActionScript 1.0; Flash Player 6

Property summary

Modifiers

Property

Description

static

BACKSPACE:Number

The key code value for the Backspace key (8).

static

CAPSLOCK:Number

The key code value for the Caps Lock key (20).

static

CONTROL:Number

The key code value for the Control key (17).

static

DELETEKEY:Number

The key code value for the Delete key (46).

static

DOWN:Number

The key code value for the Down Arrow key (40).

static

END:Number

The key code value for the End key (35).

static

ENTER:Number

The key code value for the Enter key (13).

static

ESCAPE:Number

The key code value for the Escape key (27).

static

HOME:Number

The key code value for the Home key (36).

static

INSERT:Number

The key code value for the Insert key (45).

static

LEFT:Number

The key code value for the Left Arrow key (37).

static

_listeners:Array [read-only]

A list of references to all listener objects that are registered with the Key object.

static

PGDN:Number

The key code value for the Page Down key (34).

static

PGUP:Number

The key code value for the Page Up key (33).

static

RIGHT:Number

The key code value for the Right Arrow key (39).

static

SHIFT:Number

The key code value for the Shift key (16).

static

SPACE:Number

The key code value for the Spacebar (32).

static

TAB:Number

The key code value for the Tab key (9).

static

UP:Number

The key code value for the Up Arrow key (38).

Properties inherited from class Object

constructor, __proto__, prototype, __resolve


Event summary

Event

Description

onKeyDown = function() {}

Notified when a key is pressed.

onKeyUp = function() {}

Notified when a key is released.

Method summary

Modifiers

Signature

Description

static

addListener(listener:Object) : Void

Registers an object to receive onKeyDown and onKeyUp notification.

static

getAscii() : Number

Returns the ASCII code of the last key pressed or released.

static

getCode() : Number

Returns the key code value of the last key pressed.

static

isAccessible() : Boolean

Returns a Boolean value indicating, depending on security restrictions, whether the last key pressed may be accessed by other SWF files.

static

isDown(code:Number) : Boolean

Returns true if the key specified in keycode is pressed; false otherwise.

static

isToggled(code:Number) : Boolean

Returns true if the Caps Lock or Num Lock key is activated (toggled to an active state); false otherwise.

static

removeListener(listener:Object) : Boolean

Removes an object previously registered with Key.addListener().

Methods inherited from class Object

addProperty, hasOwnProperty, isPropertyEnumerable, isPrototypeOf, registerClass, toString, unwatch, valueOf, watch



Version 8

Comments


nectil said on Sep 27, 2005 at 2:25 AM :
A problem with Mac commands: when the COMMAND key is down, no event occurs when another key is pressed! So it's impossible to know if somebody paste something with the Key listeners, you have to refer to textfield onChange listener... On Windows it works well.
Whittaker007 said on Oct 24, 2005 at 10:43 PM :
There no longer seems to be a reference for keycodes?
shimi2 said on Oct 25, 2005 at 2:55 PM :
Hi - The complete list of keycodes is here:
Current page: http://livedocs.macromedia.com/flash/8/main/00001686.html
nectil said on Jan 16, 2006 at 10:03 AM :
Key object : onKeyUp & onKeyDown issue.

Hello,

I already submit a bug report about this, but this is an additional bug and precisions.

As you probably know, Flash player on Mac OS X have a bug with the command modifier key : when the apple-key is pressed, other key events are not handled (cut-copy-paste for example).

But there is worst... one month ago, our projets was compiled in flash 7 format. Now, we compile our projects in flash 8, and this is now the issue on the WINDOWS platform:

> with Explorer, the same bug appears when a swf is in 8 format : when the CTRL key is pressed, the Cut, Copy, Paste, etc. commands are not handled ! If I compile in 7, it's OK ! with the same flash player.

> with Firefox, the commands are handled well, but, but... not the release of the CTRL key! so when you make a Copy or a Cut, it's impossible to know if the CRTL key is released.

This is to say : I know you are making a very good job and the flash technology is incredible, but please, please, resolve this 'simple' bug (okay, nothing is simple...) and update the version of flash player because it's really a big deal for RIAs developpers.

Right now, we have objects completely unusable, objects on which we spend months... and clients very angry.

Thank you very much for listening us.

François Dispaux
No screen name said on Mar 25, 2006 at 7:36 PM :
I'd like to provide a little more detail to the comment by François. If there is another key held down when CONTROL or SHIFT are released and the application is compiled for SWF8, then the keyup events are not sent.

Sarah
Me_TheKing said on May 27, 2006 at 12:07 AM :
i can't see these keys:
KEY: ,
and
KEY: .
when i use this code for example:

var keyListener:Object = new Object();
keyListener.onKeyDown = function() {
trace("For the last key typed:");
trace("\tThe Key code is: "+Key.getCode());
trace("\tThe ASCII value is: "+Key.getAscii());
trace("");
};
Key.addListener(keyListener);

but if use the SHIFT key it's works
but why i have to use the shift key.
kdmiller3 said on Jan 18, 2007 at 8:38 PM :
The comma and period keys are shortcuts to "Step Backward One Frame" and "Step Forward One Frame" in the Control menu of the flash player, so the Flash player consumes them instead of passing them along to the script. Check the "Disable Keyboard Shortcuts" option and they'll work again.
Axx said on Mar 3, 2007 at 6:56 AM :
I got stuck on this too. I couldn't trap the lowercase period or comma keys. I found the statement on another page that you should hit Control -> Disable Keyboard Shortcuts. That did the trick. (Control -> Dis on the SWF player, not the Flash environment).
Why are the period and comma keys designated shortcut keys?

 

RSS feed | Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/flash/8/main/00002294.html