2

I am using PhoneGap and I need to catch a "keyboard is showing" event on android phones.

I've found some threads saying to use the "showkeyboard" event. (This one for example : Show hide keyboard is not working propery in android phonegap)

My question : Is this an android event usable with phonegap? Is this a simple phonegap event? Is this a browser event? Is this a classical javascript event?

I don't find any doc on this event, and I need it because it's also firing on orientation change...

EDIT: I've found this, saying it's from android but undocumented : https://issues.apache.org/jira/browse/CB-6154

Community
  • 1
  • 1
Nicolas
  • 1,693
  • 1
  • 16
  • 40

1 Answers1

1

These events are from Android but are not documented. I've encountered some trouble with this so I recommend not using them.

For information, in order to make my function work, I've done something like this (this is just the general idea):

this._keyboardTimer;

document.addEventListener('showkeyboard', function (e) {
    clearTimeout(this._keyboardTimer); // keep only the last event
    this._keyboardTimer = setTimeout(function(oldOrientation){
        if (oldOrientation != getOrientation()) { 
            /* this is an orientation event */
        } else { 
            /* keyboard is really opening */
        }
    }.bind(this, getOrientation()), 200);
}.bind(this), false);

function getOrientation() {
    return ( (window.orientation == 90) || (window.orientation == -90) ) 
            ? 'landscape' 
            : 'portrait';
};

And I've done the same thing with the 'hidekeyboard' event. Hope this will help.

[EDIT] There's another problem (yirk!): keyboards may be slightly differents. If the keyboard changes for a smaller: the 'hidekeyboard' event is fired....

Nicolas
  • 1,693
  • 1
  • 16
  • 40