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: 107
Registered: ‎11-20-2009
My Device: Tegra 2 Android tablet and Playbook
My Carrier: Rogers

Is there is a way to capture event when virtual (on screen) keyboard showing?

Is there is a way to capture event when virtual (on screen) keyboard showing?

http://riahut.com
Developer
Posts: 278
Registered: ‎10-27-2010
My Device: Playbook

Re: Is there is a way to capture event when virtual (on screen) keyboard showing?

[ Edited ]

 

Yes, you can capture keyboard events: addEventListener( KeyboardEvent...

Extremely rudimentary example...

 

 

package
{
	import flash.display.Sprite;
	import flash.events.KeyboardEvent;
	import flash.text.TextField;
	import flash.text.TextFieldType;
	import flash.text.TextFormat;

	import qnx.dialog.AlertDialog;
	import qnx.dialog.DialogSize;

	[SWF(width='1024', height='600', backgroundColor='#cccccc', frameRate='30')]
	public class KeyboardEventTest extends Sprite
	{
		public function KeyboardEventTest()
		{
			// Creating a simple TextFormat
			var tf:TextFormat = new TextFormat();
			tf.font = 'Arial';
			tf.color = 0x000000;
			tf.size = 120;
			tf.align = 'left';

			// Creating the text field that you will click on
			// to bring up the keyboard
			test_text = new TextField();
			test_text.name = 'test_text';
			test_text.width = 924;
			test_text.height = 145;
			test_text.x = 50;
			test_text.y = 100;
			test_text.type = TextFieldType.INPUT;
			test_text.defaultTextFormat = tf;
			test_text.background = true;
			test_text.selectable = true;
			// setting the event listener to listen for key down events
			test_text.addEventListener( KeyboardEvent.KEY_DOWN, text_event );
			addChild( test_text );

			stage.nativeWindow.visible = true;
		}


		// capturing the event and pushing the key code into an alert.
		private var ad:AlertDialog;
		public function text_event( e:KeyboardEvent ):void
		{
			trace( e.charCode );

			// if an AlertDialog is already being shown this will hide it
			// so another AlertDialog can be displayed.
			try{ ad.cancel() }catch( err:Error ){ }

			ad = new AlertDialog();
			
			ad.title = "Keycode";
			ad.message = e.charCode.toString();
			ad.addButton( "OK" );
			ad.dialogSize= DialogSize.SIZE_SMALL; 
			ad.show( null );
		}
	}
}

 

Or are you talking about capturing other events while the keyboard is on screen?  You should be able to handle any events that are triggered while your application is running.

--------------
kdittyr

Accepted PlayBook Applications:
HDB Converter -- Utilities/Calculators
Developer
Posts: 107
Registered: ‎11-20-2009
My Device: Tegra 2 Android tablet and Playbook
My Carrier: Rogers

Re: Is there is a way to capture event when virtual (on screen) keyboard showing?

[ Edited ]

Thank you for your reply, but this is not what I need, obviously I know how to capture keyboard event!!!

 

What I need is to know how to capture moment when keyboard displayed on screen and hidden from the screen. Also action Hide the keyboard can be never captured by key up/down event....

http://riahut.com
Developer
Posts: 278
Registered: ‎10-27-2010
My Device: Playbook

Re: Is there is a way to capture event when virtual (on screen) keyboard showing?

[ Edited ]

I guess I misunderstood your original question...  the wording was a little odd.  Sorry.

 

"Also action Hide the keyboard can be never captured by key up/down event..."

I never said it would be.

--------------
kdittyr

Accepted PlayBook Applications:
HDB Converter -- Utilities/Calculators
Developer
Posts: 107
Registered: ‎11-20-2009
My Device: Tegra 2 Android tablet and Playbook
My Carrier: Rogers

Re: Is there is a way to capture event when virtual (on screen) keyboard showing?

I guess I didnt explained myself properly. I'm pretty sure shoul be something in core library for this purposes, othervise how do I know that keyboard not hiding part of my UI !?

http://riahut.com
Developer
Posts: 2,462
Registered: ‎11-04-2010
My Device: Bold 9700

Re: Is there is a way to capture event when virtual (on screen) keyboard showing?

hey ectar,

 

currently there are no APIs in place that tell the application that the keyboard is visible. however you can engineer a way to work around that.

 

assuming a keyboard only pops up whenever a user is inputting a value into some sort of field, you can add an eventlistener to all your TextField inputs, TextInput, etc. using this code:

 

 

yourInputObject.addEventListener(FocusEvent.FOCUS_IN, yourFunction);

 

 

so everyime someone clicks on your input object it triggers a function. so you are not directly getting a signal from the keyboard but using intuition you can know when the keyboard will be on screen. also you can add an eventlistener to perform a function when the keyboard is off screen:

 

 

yourInputObject.addEventListener(FocusEvent.FOCUS_OUT, yourOtherFunction);

 

now because this is a work around, there is a draw back. the only time when you cant "predict" when a keyboard will be on screen is if the user does the swipe action from the bezel to pop the keyboard up. also if you are using the QNXStageWebView object you probably wouldnt know if the keyboard is up for an input field within that object either.

 

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
Developer
Posts: 107
Registered: ‎11-20-2009
My Device: Tegra 2 Android tablet and Playbook
My Carrier: Rogers

Re: Is there is a way to capture event when virtual (on screen) keyboard showing?

Thank you, this is exactly how I've implemented it right now Smiley Happy

But this is not scalable approach, what if I will have 125 Input elements Smiley Happy this will be serious overhead and also your listed drawback  dont make me entirely happy.

 

I think I will be using focus for now, I hoping API will have this feature in the future. I think this will be usefull to all and everybody.

http://riahut.com
Developer
Posts: 6,541
Registered: ‎10-27-2010
My Device: HTC One, PlayBook, LE Z10, DE Q10
My Carrier: Verizon

Re: Is there is a way to capture event when virtual (on screen) keyboard showing?

Ideally, you would be able to listen for keyboard display events.  Might want to add that as a feature request to the BB issue DB.  I know I could use that in a future application.

Developer
Posts: 107
Registered: ‎11-20-2009
My Device: Tegra 2 Android tablet and Playbook
My Carrier: Rogers

Re: Is there is a way to capture event when virtual (on screen) keyboard showing?

Yes, and I snooped thought all QNX events looking for something like that Smiley Happy

Where can I post feature request?

http://riahut.com
Developer
Posts: 6,541
Registered: ‎10-27-2010
My Device: HTC One, PlayBook, LE Z10, DE Q10
My Carrier: Verizon

Re: Is there is a way to capture event when virtual (on screen) keyboard showing?