title: DispatchKeyEvent Android
body: <p>I would capture the keycode of the keyboard when an user tape a text in my application, this code it works fine with the android emulator but in real device the toast doesn't work :</p>
  
  <pre><code>public class MainActivity extends ActionBarActivity implements OnKeyListener {
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main); 
      }
  
      @Override
      public boolean dispatchKeyEvent(KeyEvent event) {
          Toast.makeText(this, "Key dispatch : "+   String.valueOf(event.getKeyCode()),Toast.LENGTH_SHORT).show();
          return super.dispatchKeyEvent(event);
      }
  
      @Override
      public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
          Toast.makeText(this, "Key onKey :" + String.valueOf(event.getKeyCode()), Toast.LENGTH_SHORT).show();
          return true;
      }
  }
  </code></pre>