title: onKeyDown() in Android not working for virtual keys
body: <p>I had been searching a lot about this thing, but could not figure it out. So I thought to ask here what exactly the problem I am facing, so that it could help others also (who might face the same problem)</p>
  
  <p>I am having the following code in my Activity</p>
  
  <pre><code>public class MainActivity extends ActionBarActivity implements KeyEvent.Callback{
      @Override
      public boolean onKeyDown(int keyCode, KeyEvent event) {
          System.out.println("Key down called");
          if ( keyCode == KeyEvent.KEYCODE_MENU ) {
              System.out.println("Menu clicked");
              return true;
          }
          return super.onKeyDown(keyCode, event);
      }
  
      @Override
      public boolean onKeyUp(int keyCode, KeyEvent event) {
          System.out.println("On key up");
          if ( keyCode == KeyEvent.KEYCODE_MENU ) {
  
              System.out.println("up Menu clicked");
              return true;
          }
          return super.onKeyUp(keyCode, event);
      }
  }
  </code></pre>
  
  <p><strong>Where it works</strong> (Devices having physical buttons)</p>
  
  <p>If I run the same code in Android device having the <strong>physical keys</strong> at the bottom then these methods are getting called for <code>Menu</code> button and <code>Back</code> button.</p>
  
  <p><strong>The Problem</strong> (Devices having virtual keys)</p>
  
  <p>But if I run the code in a device having the <a href="https://developer.android.com/training/system-ui/navigation.html" rel="nofollow">Virtual keys</a> at the bottom (rather than the physical keys) then these methods are <strong>NOT</strong> being called.</p>
  
  <p>I am able to handle the back press (thanks to <code>onBackPressed()</code>) but not able to override the Menu button pressed for virtual keys.</p>
  
  <p>Any workaround for this thing? How can I override the menu button in Android devices having Virtual keys.</p>
  
  <p>Thanks.</p>