Adobe
Products

Top destinations

  • Adobe Creative Cloud
  • Creative Suite
  • Adobe Marketing Cloud
  • Acrobat
  • Photoshop
  • SiteCatalyst
  • Students
  • Elements family

Adobe Creative Cloud

  • What is Adobe Creative Cloud?
  • Design
  • Web
  • Photography
  • Video
  • Students
  • Teams
  • Enterprise
  • Educational institutions

Design and photography

  • Photoshop
  • Illustrator
  • InDesign
  • Adobe Muse
  • Lightroom

Video

  • Adobe Premiere
  • After Effects

Web development and HTML5

  • Edge Tools & Services [opens in a new window]
  • Dreamweaver
  • Gaming [opens in a new window]

Adobe Marketing Cloud

  • What is Adobe Marketing Cloud?
  • Digital analytics
  • Social marketing
  • Web experience management
  • Testing and targeting
  • Media optimization

Analytics

  • SiteCatalyst
  • Adobe Discover
  • Insight

Social

  • Adobe Social

Experience Manager

  • CQ
  • Scene7

Target

  • Test&Target
  • Recommendations
  • Search&Promote

Media Optimizer

  • AdLens
  • AudienceManager
  • AudienceResearch

Document services

  • Acrobat
  • EchoSign [opens in a new window]
  • FormsCentral [opens in a new window]
  • SendNow [opens in a new window]
  • Acrobat.com [opens in a new window]

Publishing

  • Digital Publishing Suite

  • See all products
Business solutions

By business need

  • Digital analytics
  • Digital publishing
  • Document management
  • Media optimization
  • Social marketing
  • Testing and targeting
  • Video editing and serving
  • Web development [opens in a new window]
  • Web experience management
  • See all business needs

By industry

  • Broadcast
  • Education
  • Financial services
  • Government
  • Publishing
  • Retail
  • See all industries
Support & Learning

I need help

  • Products
  • Adobe Creative Cloud
  • Adobe Marketing Cloud
  • Forums [opens in a new window]

I want to learn

  • Training and tutorials
  • Certification [opens in a new window]
  • Adobe Developer Connection
  • Adobe Design Center
  • Adobe TV [opens in a new window]
  • Adobe Marketing Center
  • Adobe Labs [opens in a new window]
Download
  • Product trials
  • Adobe Flash Player
  • Adobe Reader
  • Adobe AIR
  • See all downloads
Company
  • Careers at Adobe
  • Investor Relations
  • Newsroom
  • Privacy
  • Corporate Social Responsibility
  • Customer Showcase
  • Contact us
  • More company info
Buy
  • For personal and professional use
  • For students, educators, and staff
  • For small and medium businesses
  • Volume Licensing
  • Special offers
  • Adobe Marketing Cloud sales [opens in a new window]
Search
 
Info Sign in
Why sign in? Sign in to manage your account and access trial downloads, product extensions, community areas, and more.
Welcome,
My Adobe
My orders
My information
My preferences
My products and services
Sign out
My cart
Privacy My Adobe
Adobe
Products Sections Buy   Search  
Solutions Company
Help Learning
Sign in Sign out Privacy My Adobe
Preorder Estimated Availability Date. Your credit card will not be charged until the product is shipped. Estimated availability date is subject to change. Preorder Estimated Availability Date. Your credit card will not be charged until the product is ready to download. Estimated availability date is subject to change.
Qty:
Purchase requires verification of academic eligibility
Subtotal
Promotions
Estimated shipping
Tax
Calculated at checkout
Total
Review and Checkout
Adobe Developer Connection / Gaming /

Capturing soft key input

by Sunil Bhaskaran

Sunil Bhaskaran

Content

  • Handling soft key events
  • The Home soft key
  • Where to go from here

Modified

10 October 2011

Page tools

Share on Facebook
Share on Twitter
Share on LinkedIn
Bookmark
Print
Adobe AIRAndroidFlash BuilderFlash Professionalgame developmentgamingmobile
Was this helpful?
Yes   No

By clicking Submit, you accept the Adobe Terms of Use.

 
Thanks for your feedback.

Requirements

Prerequisite knowledge

Familiarity with ActionScript 3.

 

Additional Requirements

  • A mobile device supporting Android 2.2 or higher.
  • Android SDK

User level

Intermediate

Required products

  • Flash Builder (Download trial)
  • Flash Professional CS5 (Download trial)

Sample files

  • SoftKeysTest.zip
  • SoftKeysTest-android-apk.zip

In Adobe AIR applications, an event is dispatched when a specific activity happens. For example, Adobe AIR generates a keyboard event whenever you press or release a key on the keyboard. Each key is identified by a unique key code. Adobe AIR extends this support to the soft keys used on mobile devices, such as Back, Menu, and Search.

In this article, you will learn about handling soft key events.

Handling soft key events

When you press any of the soft keys, the NativeApplication object dispatches the keyboard  event, KeyboardEvent.KEY_DOWN. Similarly, when you release the key, the NativeApplication object dispatches the event, KeyboardEvent.KEY_UP. You can handle these events and provide the appropriate behavior for these keys when you develop an application.

For example, consider a mobile application in which you have a collection of records. When you press the Back key, you want to display the previous record in the collection. By default, when you press the Back key on an Android device, an Adobe AIR application moves to the background and the phone reactivates the previously active application. Handling the keyboard events that are generated from pressing the Back key allows you to prevent this default behavior and program the application to behave in the way you want.

Note: You must handle the keyDown event when you want to cancel the default behavior of the BACK key. The keyUp event is too late in the event chain.

You can listen for keyboard events on the NativeApplication object. Use the following statement to add a listener for the keyDown event: 

NativeApplication.nativeApplication.addEventListener(KeyboardEvent.KEY_DOWN,checkKeypress);

In the following example, the checkKeypress function illustrates how you can test the dispatched KeyboardEvent object to determine which key was pressed. The function uses a switch statement to provide specific behavior for the soft key that is pressed. Other key presses are ignored.

public function CheckKeypress(event:KeyboardEvent):void { switch (event.keyCode) { case Keyboard.BACK: event.preventDefault(); trace("Back key is pressed."); break; case Keyboard.MENU: trace("Menu key is pressed."); break; case Keyboard.SEARCH: trace("Search key is pressed."); break; } }

When designing your application, it is very important to handle the soft keys in a way that is consistent with the native applications on the platform. Otherwise, users may become frustrated when your application doesn't respond in the way they expect. For example, on the Android platform, the Back key is used to return to a previous view of the application until you reach the initial view. From the initial view, another press of the Back key deactivates the current application and reactivates the previous application or the phone Home screen. In an Adobe AIR application, you must keep track of the application state in order to emulate this native behavior. If you do nothing, the Back key will deactivate your application, no matter what state or view it is in.

The Home soft key

A keyboard event is not dispatched when the Home key is pressed. Your application is deactivated and this cannot be prevented. However, the NativeApplication object does dispatch a deactivate event. In the deactivate event handler, you should take the following actions to save battery power and to prepare for possible termination:

  • Save application state
  • Remove event listeners from the Accelerometer and Geolocation objects
  • Stop audio playback
  • Throttle the application frame rate

Note: AIR automatically throttles the frame rate of background applications to four frames-per-second. You can save even more battery power by setting the frame rate to .01, if your application does not have any persistent network connections.

To restore an application, you can use either the activate event or the invoke event. An activate event is dispatched when your application is brought back to the foreground, but not when your app is launched initially. An invoke event is dispatched when your application is brought to the foreground and also when it is launched initially.

Where to go from here

In this article, you learned about handling soft key events. For more information, refer to Basics of handlingevents in the online documentation. 

More Like This

  • Using the StageWebView class
  • Capturing video input in a mobile AIR application
  • Using the Adobe AIR Geolocation APIs on Android
  • Using the tel: and sms: URIs in a mobile phone application

Products

  • Adobe Creative Cloud
  • Creative Suite
  • Adobe Marketing Cloud
  • Acrobat
  • Photoshop
  • Digital Publishing Suite
  • Elements family
  • SiteCatalyst
  • For education

Download

  • Product trials
  • Adobe Reader
  • Adobe Flash Player
  • Adobe AIR

Support & Learning

  • Product help
  • Forums

Buy

  • For personal and professional use
  • For students, educators, and staff
  • For small and medium businesses
  • Volume Licensing
  • Special offers

Company

  • News room
  • Partner programs
  • Corporate social responsibility
  • Career opportunities
  • Investor Relations
  • Events
  • Legal
  • Security
  • Contact Adobe
Choose your region United States (Change)
Choose your region Close

North America

Europe, Middle East and Africa

Asia Pacific

  • Canada - English
  • Canada - Français
  • Latinoamérica
  • México
  • United States

South America

  • Brasil
  • Africa - English
  • Österreich - Deutsch
  • Belgium - English
  • Belgique - Français
  • België - Nederlands
  • България
  • Hrvatska
  • Česká republika
  • Danmark
  • Eastern Europe - English
  • Eesti
  • Suomi
  • France
  • Deutschland
  • Magyarország
  • Ireland
  • Israel - English
  • ישראל - עברית
  • Italia
  • Latvija
  • Lietuva
  • Luxembourg - Deutsch
  • Luxembourg - English
  • Luxembourg - Français
  • الشرق الأوسط وشمال أفريقيا - اللغة العربية
  • Middle East and North Africa - English
  • Moyen-Orient et Afrique du Nord - Français
  • Nederland
  • Norge
  • Polska
  • Portugal
  • România
  • Россия
  • Srbija
  • Slovensko
  • Slovenija
  • España
  • Sverige
  • Schweiz - Deutsch
  • Suisse - Français
  • Svizzera - Italiano
  • Türkiye
  • Україна
  • United Kingdom
  • Australia
  • 中国
  • 中國香港特別行政區
  • Hong Kong S.A.R. of China
  • India - English
  • 日本
  • 한국
  • New Zealand
  • 台灣

Southeast Asia

  • Includes Indonesia, Malaysia, Philippines, Singapore, Thailand, and Vietnam - English

Copyright © 2013 Adobe Systems Incorporated. All rights reserved.

Terms of Use | Privacy | Cookies

Ad Choices

Reviewed by TRUSTe: site privacy statement