Join Now
Quality Rating:
  • Currently 0.0 / 5
(0.0 / 5 - 0 votes cast)
Expertise Level:
  • Currently 0.0 / 5
(0.0 / 5 - 0 votes cast)

This page was last modified 18:34, 6 April 2008.

How to handle keypress events

From Forum Nokia Wiki


Compatibility: Flash Lite: 1.1, 2.x

Contents

Handling keypress event using the on handler

A way to handle a keypress event is using this statement:
on(keyPress aKeyCode) {A command handling code}


This example shows you how to handle "Up" and "9" keypress events:

  • Using the Text tool, drag a static text field outside your document.

Image:Handle_keyevent.jpg

  • Convert this text into a button: Select the text field -> Right click -> Convert to Symbol -> Select Button
  • Open the Actions panel and add the following code:
on(keyPress "<Up>") 
{
     trace("You have pressed the Up key");
     //Add your command handling code here
}
 
on(keyPress "9") 
{
     //Add your command handling code here
}

List of key constants

To handle the Soft Keys, you must first call the SetSoftKeys command.

Device button Keypress code
0-9, *, # 0-9, *, #
Left Arrow key <Left>
Right Arrow key <Right>
Up Arrow key <Up>
Down Arrow key <Down>
Select key <Enter>
Left soft key <PageUp>
Right soft key <PageDown>


Handling keypress events using a key listener (Flash Lite 2.x only)

//Create a listener object named keyListener 
var keyListener:Object = new Object();
 
//Define a function that responds to the KeyDown event
keyListener.onKeyDown = function()
   {
    if (Key.getCode() == Key.UP)
    {
        trace("You have pressed the Up key");
        //Add your command handling code here
    } 
    else
    {
        trace("You have pressed: "+Key.getCode()); 
    }
};
//The keyListener object is then registered to the Key object
Key.addListener(keyListener);

For handling the Soft Keys using a key listener, see Flash Lite 2.0 Soft Keys Example

Download

You can download an example with source code here:
Image:handle_key_events.jpg
Handling keypress event using the on handler 240*320 (swf + fla)

Related Discussions
Thread Thread Starter Forum Replies Last Post
VERY URGENT: views and dialogs djazia Symbian User Interface 2 2005-05-13 02:50
window handle MaryVince Symbian User Interface 3 2006-04-12 15:11
Fep example question stefano.garusi General Symbian C++ 2 2006-11-30 08:14
help urgent.....Showing a message on receiving an sms Chinu Symbian Networking & Messaging 11 2007-11-03 04:05
about outgoing call... marycore General Symbian C++ 5 2004-12-07 05:57
 
Powered by MediaWiki