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

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

In addition to capturing event, it would be nice to actually programmatically show/hite keyboard as well.

http://riahut.com
Please use plain text.
Developer
peter9477
Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10

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

There is as yet still no programmatic way to open/close the keyboard, nor a documented way to receive an event when it pops up, but for now there's a temporary workaround that should let you at least discover whether the keyboard is showing or not.

 

Underlying much of the system messaging on the PlayBook is a wonderful QNX service called the Persistent Publish-Subscribe (PPS) mechanism.  (I've written a tiny bit about it before, with background links.)  The as-yet-undocumented qnx.pps package will have numerous classes in it to assist with that, and presumably at some point we'll have full documentation on what's available.

 

In the beta3 release, there's a file at /pps/system/keyboard/status that can be read to find the keyboard state.  You'll have to do some minor parsing for now (until the qnx.pps stuff is made available), but a simple regex would suffice for a start.  Here's the initial content of that on my system:

 

$ cat /pps/system/keyboard/status
@status layout::automatic layoutsAvailable:json:["automatic","azerty","qwerty","qwertz"] showPopup:b:true size:n:312 type::default visible:b:false

Now one of the beautiful things about the PPS objects is that they aren't real files, and you can read them in different ways.  If you append "?delta,wait" to the filename, you can receive updates whenever they occur. If you were to set up an asynchronous FileStream you could receive an event whenever there are updates, and among the updates you'll see are changes in the visible status, like this:

 

$ cat /pps/system/keyboard/status?delta,wait
... (same stuff as above)
@status visible:b:true @status visible:b:false @status visible:b:false

Note the addition of "?delta,wait", which you would use with FileStream.openAsync().   When the first @status plus "visible:b:true" comes out, I manually opened the keyboard (BottomLeft swipe).  When the next four lines came out, I had manually closed it again.  (The duplicate pair showing false is either a bug or just something to ignore.)

 

 

This is all totally undocumented for now, but I believe some variation on the above will eventually be wrapped with appropriate APIs (in qnx.pps).  You won't have to deal with FileStreams and you won't have to parse the updates yourself, but the basic concept will, I believe, survive through to the released product.  Or maybe they won't even manage to get this all supported and documented before release, in which case a post-release update should have it.

 

 

Caveat: it may also just all get removed.  Who knows... :smileyhappy:


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!
Please use plain text.
Developer
peter9477
Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10

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

[ Edited ]

I noticed (as others have before, I guess) that the SDK actually includes the qnx.pps stuff even though it's currently undocumented.  (Caveat #1: for good reason, no doubt... undocumented stuff is expected to change!)

 

A bit of poking let me build the following sample, which demonstrates two key capabilities:

  1. programmatic control of the keyboard state (shown/hidden), using the also-undocumented qnx.input.IMFConnection
  2. event handling when keyboard visibility changes, using the aforementioned PPS info and the qnx.pps.PPS class

Caveat #2: even if this stuff doesn't change, I might well not be doing this correctly!

 

Here's the code.  It has no GUI elements of its own, but opens the keyboard on launch.  It then watches for you to hide it.  There are trace() calls for various conditions.  If you open the keyboard manually, it will set up a timer and close it automatically after 5 seconds (yep, even while you're typing on it!).  The bonus is that the PPS parsing is all handled for you.

 

package {
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.utils.setTimeout;
    import flash.utils.clearTimeout;

    import qnx.pps.PPS;
    import qnx.events.PPSEvent;
    import qnx.input.IMFConnection;

    [SWF(backgroundColor="#CCCCCC", frameRate="20")]
    public class KeyboardTest extends Sprite {
        private var imf:IMFConnection;
        private var pps:PPS;
        private var keyboard_visibility:Boolean = false;
        private var timeout_id:uint;

        public function KeyboardTest() {
            imf = IMFConnection.imfConnection;
            imf.showInput();
            trace("timeout", timeout_id);

            pps = new PPS();
            if (pps.open('/pps/system/keyboard/status', PPS.O_RDONLY)) {
                pps.addEventListener(PPSEvent.PPS_CHANGED, onKeyboardStatus);
                keyboard_visibility = pps.data['visible'];
            }
        }

        private function hideLater():void {
            trace("auto-hiding");
            imf.hideInput();
        }

        private function onKeyboardStatus(e:Event):void {
            for (var k:String in pps.data)
                trace("data", k, pps.data[k]);

            var new_visibility:Boolean = pps.data['visible'];
            // detect change in visibility
            if (new_visibility != keyboard_visibility) {
                trace("visibility changed");
                if (!new_visibility) {
                    trace("keyboard hidden");
                    if (timeout_id)
                        clearTimeout(timeout_id);
                }
                else {
                    trace("now visible, auto-hide in 5 seconds");
                    timeout_id = setTimeout(hideLater, 5000);
                }

            // remember for next time
            keyboard_visibility = new_visibility;
            }
        }
    }
}

 

 

Caveat #3, 4, and 5: Really, if you don't absolutely need this, I wouldn't use it yet.  As you can see, it's technically quite feasible for this stuff to be available, so it's a question of when, but more importantly how.  They may have plans to make the PPS stuff all transparent to us for 90% of the use cases, and they certainly may plan to juggle the APIs, the /pps hierarchy, the names of any individual data items (e.g. "visible"), and so on.

 

Caveat #6: as I said in the previous post, this stuff may all just be removed by the time the product is released, and access to the above /pps tree may be prevented.  I doubt that will happen, but it's your neck if you rely on it and get fried.

 

I'd certainly suggest that if you need help using any of the above, you should probably not use it until it's all documented and stable.  I would say it's probably useful for educational purposes, helping you understand the PlayBook and QNX architecture, if nothing else.

 

Enjoy! :smileyhappy:


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!
Please use plain text.
Developer
JRab
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?

well played sir :smileyhappy:

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
Please use plain text.
Developer
ChernyshovYuriy
Posts: 116
Registered: ‎11-18-2010
My Device: BlackBerry PlayBook

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

At SDK 1.0.1 this:

pps.addEventListener(PPSEvent.PPS_CHANGED, onKeyboardStatus)

doesnt work....

 

Please use plain text.
New Contributor
ollieollie82
Posts: 6
Registered: ‎01-19-2011
My Device: Not Specified

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

this is extremely annoying.

 

In 101, my textarea no longer automatically pops up the keyboard event so I'd like to know when the keyboard is on the screen, otherwise I cannot resize my textarea accordingly. ugh.

 

Does anyone know of a working API call for this in 101?  Better yet, does anyone know how to force the keyboard to display?

Please use plain text.
Developer
peter9477
Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10

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

The earlier post shows how you can force the keyboard to display, but at the moment nobody seems to know a method of reliably determining the current status of the keyboard.

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!
Please use plain text.
New Contributor
harry4000
Posts: 2
Registered: ‎11-29-2011
My Device: PlayBook

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

Are there any updates to this in AIR 3?  Do the native abilities allow a library to be written that can access PPS and then report the status to the Flex app?

Please use plain text.
Developer
peter9477
Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10

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

It's been supported in AIR for a couple of versions now. Look for something like VirtualKeyboardEvent.

You could also access PPS directly, but there would be no need as the NDK does include direct support for receiving these events as well, and with an ANE it could be exposed to AIR. There's just no point doing that since it already is exposed in standard APIs.

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!
Please use plain text.
BlackBerry Development Advisor
jdolce
Posts: 172
Registered: ‎10-25-2010
My Device: Not Specified
Please use plain text.