Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Adobe AIR Development

Reply
Developer
Posts: 409
Registered: ‎12-10-2010
My Device: PlayBook
My Carrier: N/A
Accepted Solution

Capturing Keyboard Events?

 

 

how is it possible to listen for keyboard events, such as the return key being pressed?  i understand the ReturnKeyType class isn't not yet working for the QNX InputText component, but even when it is i'm not sure it will include keyboard events or if it will be simply a visual change to the keyboard's return button.

 

i plan on using the flash.text.TextField class (for portability) instead of qnx.ui.text.InputText.  currently, the keyboard will activate and disappear if the flash.text.TextField receives or loses focus.  however, these text fields are data entry fields so i would like to listen for the return key press on the keyboard so that i can both save the data entered and remove the keyboard from the screen - or perhaps more simply, just allow the text field to listen for when it loses focus to save the data and allow the keyboard to disappear.  but how can i activate either by pressing return on the keyboard?


PlayBook Applications:
Drop Swatch
Developer
Posts: 2,462
Registered: ‎11-04-2010
My Device: Bold 9700

Re: Capturing Keyboard Events?

hey darkin,

 

you can acheive this by using a listener to listen for key presses on your input object such as a textfield and responding based on what keys are being pressed. in your case you would be listening for the enter key and perform your actions such as taking away the focus and the onscreen keyboard. you can use the program below as a reference as to how this can be done:

 

 

package
{
	import flash.display.Sprite;
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
	import flash.events.KeyboardEvent;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	import flash.text.TextFieldType;
	import flash.ui.Keyboard;
	
	[SWF(width="1024",height="600",backgroundColor="#CCCCCC",frameRate="30")]
	public class TextFieldTest extends Sprite
	{

		private var myInput:TextField;
		
		public function TextFieldTest()
		{
			super();
			
			
			// support autoOrients
			stage.align = StageAlign.TOP_LEFT;
			stage.scaleMode = StageScaleMode.NO_SCALE;
			
			myInput = new TextField();
			myInput.width = 300;
			myInput.height = 50;
			myInput.type = TextFieldType.INPUT;
			
			/*
			 * listen for what keys are being pressed and react with
			 * onKeyDown function
			*/
			myInput.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
			
			addChild(myInput);
			
		}
		private function onKeyDown(e:KeyboardEvent):void
		{
			/*
			 * You can listen for any key presses under the
			 * flash.ui.Keyboard class. it has all the constants
			 * such as .ENTER, .END, etc
			*/
			if (e.keyCode == Keyboard.ENTER)
			{
				trace("You just entered");
				
				/*
				 * Steal focus away from the textfield object
				 * focus can be set to anywhere and the keyboard 
				 * will disappear
				*/
				
				stage.focus = null;
				
				/*
				 * Perform other actions such as saving data
				*/
			}
		}

	}
}

 

 

 

hope that helps. good luck!

 

J. Rab (Blog) (Twitter)
--
1. If you liked my post or found it useful please click on the thumbs up and provide a Like!
2. If my post solved your problem please click on the Accept as Solution button. Much appreciated!

Approved Apps: OnTrack | ssShots | Hangman
Highlighted
Developer
Posts: 6,541
Registered: ‎10-27-2010
My Device: HTC One, PlayBook, LE Z10, DE Q10
My Carrier: Verizon

Re: Capturing Keyboard Events?

You will need to add an event listener to your control.  You will need to test which method works best for you, but try either:

 

this.address.addEventListener( KeyboardEvent.KEY_UP, KeyChange );
this.address.addEventListener( FocusEvent.FOCUS_OUT, FocusOutChange );

 

Contributor
Posts: 17
Registered: ‎11-27-2010
My Device: Not Specified

Re: Capturing Keyboard Events?

Hi,

 

Can we capture the key events keypanel.JPGfor Blackberry panel buttons as shown in picture??

Developer
Posts: 153
Registered: ‎10-26-2010
My Device: Bold 9900
My Carrier: AT&T

Re: Capturing Keyboard Events?

[ Edited ]

Balavenkatesh wrote:

Hi,

 

Can we capture the key events for Blackberry panel buttons as shown in picture??


Hi,

 

    Those buttons don't exist on the PlayBook unless you create them onscreen and then yes, you can capture their events

 

Harry.

--------------
Accepted PlayBook Applications: Marmi-doos, BASIC, Run and Hide, SuperClip
Accepted OS4-7 SmartPhone App: KeepLightOn
Contributor
Posts: 17
Registered: ‎11-27-2010
My Device: Not Specified

Re: Capturing Keyboard Events?

Hi Harry,

 

Thank your for your reply.Smiley HappySmiley Happy The thing now is how can i capture that events like "back button" or "disconnect(red button)"  in html or JavaScript code??

 

Because my need is that, when we call to somebody after call is done i will disconnect the call and after disconnecting i have to invoke the Calendar API. I am Struggling with that...Smiley SadSmiley SadSmiley Sad

Developer
Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10
My Carrier: none

Re: Capturing Keyboard Events?

I think you're in the wrong forum.  This forum is for the PlayBook, as in RIM's new tablet running the QNX OS.  There are no "calls" and, so far, no calendar API.  Sounds like you're looking for a forum about development for one of the phones.  Maybe the Java one?  Or the web development forum?


Peter Hansen -- (BB10 and dev-related blog posts at http://peterhansen.ca.)
Author of White Noise and Battery Guru for BB10 and for PlayBook | Get more from your battery!
Contributor
Posts: 17
Registered: ‎11-27-2010
My Device: Not Specified

Re: Capturing Keyboard Events?

Hi Peter, Thank you for your reply. But can we capture the events for those buttons as i mentioned there??

Developer
Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10
My Carrier: none

Re: Capturing Keyboard Events?

 


Balavenkatesh wrote:

Hi Peter, Thank you for your reply. But can we capture the events for those buttons as i mentioned there??


 

Yes, you can capture those events.

 

But not on the PlayBook, as it doesn't have such buttons.

 

And this forum is for the PlayBook Tablet OS SDK for Adobe AIR, so continuing to ask about it here is kind of silly.

 


Peter Hansen -- (BB10 and dev-related blog posts at http://peterhansen.ca.)
Author of White Noise and Battery Guru for BB10 and for PlayBook | Get more from your battery!