Mercurio Cromo
Mercurio Cromo

Reputation: 69

Detect Hide Keyboard Button on Ipad Iphone in Javascript

I am trying to intercept "Hide keyboard button" specific for Ipad in Javascript. I searched everywhere but could not find correct keycode for that. I pressed any keys and I get a keycode map (for characters, but also for enter, space and delete..).

This is an example of what I want to accomplish

$( "#mydiv" ).on( "keydown", function( event ) {
   if (event.which == xx){
      //do something
    }
}

where xx is my keycode on 'hide keyboard button'. No method is called to the delegate when the button is pressed nor a KeyCode.

I took a look at detect iPad keyboard Hiding button, but I get a solution on a different level (with Xcode), but I need a solution with Javascript.

Hope someone could help.

enter image description here

Upvotes: 3

Views: 2090

Answers (1)

Mercurio Cromo
Mercurio Cromo

Reputation: 69

I found a workaroud for iPad IOS7. I will test on IOS8 to make sure it works. So basically I create a listener on every FOCUSOUT event (for all my texts) and I call my function.

It fires when you have your keyboard open and when you close your "keyboard". It doesn't fire when you select another text field or button, because it targets on null. If you use in combination with keydown, you can save multiple value and call your submit function only when you release your keyboard. It works for my specific project.

 document.addEventListener('focusout', function(e) {
   if (e.relatedTarget === null) {
     alert("close keyboard without click on something else");
     callYourFunction();
   }
 });

p.s I'm pretty new here in SO, so I don't know if I can reply myself or I should edit my question or make a comment.

Upvotes: 3

Related Questions