Skip to content Skip to sidebar Skip to footer

Where Is The "showkeyboard" Event Coming From?

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 : Sho

Solution 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 eventthis._keyboardTimer = setTimeout(function(oldOrientation){
        if (oldOrientation != getOrientation()) { 
            /* this is an orientation event */
        } else { 
            /* keyboard is really opening */
        }
    }.bind(this, getOrientation()), 200);
}.bind(this), false);

functiongetOrientation() {
    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....

Post a Comment for "Where Is The "showkeyboard" Event Coming From?"