Dinedal
Dinedal

Reputation: 2696

How do I Capture native (Menu) button presses in PhoneGap?

By calling BackButton.override(); and then hooking on to the backKeyDown event, I am able to get the back button press to register.

But there doesn't appear to be a MenuButton.override(); Also, hooking on the menuKeyDown doesn't register a button press.

Here's my (non-functional) code. What am I missing?

<script type="text/javascript" charset="utf-8" src="phonegap.js"></script>      

  <script type="text/javascript" charset="utf-8">
        document.addEventListener("deviceready", function() {

            alert('initialized');
    }, false);
    document.addEventListener("menuKeyDown", function() {

            alert('menu_pressed'); // Never happens
    }, false);
  </script>

Upvotes: 3

Views: 5136

Answers (1)

UVM
UVM

Reputation: 9914

The latest version of phongap.js does not support overriding menu key for this edit you copy add the following code:

KeyEvent.prototype.menuTrigger = function()
{
  var e = document.createEvent('Events');
  e.initEvent('menuKeyDown');
  document.dispatchEvent(e);
}

Hope this will help you.

Upvotes: 2

Related Questions