KeyEvents

From Gnash Project Wiki

Jump to: navigation, search

Contents

Types of key events

  • KeyDown;
  • KeyUp;
  • Keypress.

Types of key event handlers

PlaceObject2 defined

These are key event hanlders specified by PlaceObject2 tags, in term as "onClipEvent handlers"

  • KeyUp (eg. onClipEvent(keyUp) {} )
  • KeyDown (eg. onClipEvent(keyDown) {} )
  • KeyPress (eg. on(keyPress "<Left>") {} )

ActionScript(user)defined

These are key event hanlders defined by ActionScript, in term as "user defined handlers"

  • onKeyUp (eg. myMovieClip.onKeyUp=function () {}; )
  • onKeyDown (eg. myMovieClip.onKeyDown=function () {}; )

Types of key listeners

Key listeners are objects that contains key event handlers, and the objects can receive related key events.

  • Movieclip and Button objects, these are the only objects for which both onClipEvent handlers and user defined handlers are valid.
  • general Object objects(except Movieclip and Buttion objects), these are objects for which only user defined handlers are valid.

Tips for handling key events

  • Keypress event is specific to a particular key, while KeyDown and KeyUp events are not;
  • Keypress event has no valid user defined handler, while KeyDown and KeyUp do have;
  • user defined key event handlers will not be automatically triggered unless the object is registers to the global Key object.
  • when pressing a key, KeyDown event handler will be invoked first and then Keypress; when releasing a key, KeyUp event handler will be invoked.
  • the global Key object can be overrided(eg. "_global.Key = 3;" is valid expression).
Note1: any testcases conflict with the above conclusion are highly welcome!
Note2: we can't assume that conclusions for key events hold true for mouse events.

Testcases

user defined key event handlers won't be triggered for static movieclips unless they are registered

  • Description
frame2: place a static movieclip named "mc" with both onClipEvent handlers and user defined handlers defined;
frame3~frame30: do nothing;
frame31: add(register) "mc" to the global Key object.
  • Observable behaviour
from frame2~frame30: if any key is pressed and released, onClipKeyDown and onClipKyeUp handlers will be  
triggered, user defined onKeyDown and onKeyUp handlers will *not* be triggered.
at frame 31: if any key is pressed and released, onClipKeyDown, onKeyDown, onClipKeyUp and  onKeyUp 
handlers will be invoked in order. onClipKeyPress never get triggered just because there is no valid key 
code provided in the testcase(how to do that?).
  • testcase
key_event_test.swf

References

Note: This is a good article to illustrate the concept of event model, but bogus for implementing a player for gnash developers!