title: How to get keyCode in android
body: <p>I have the following code:</p>
  
  <pre><code>tv.setOnKeyListener(new View.OnKeyListener() {
          public boolean onKey(View v, int keyCode, KeyEvent event) {
           switch(keyCode) 
              {
                  case KeyEvent.KEYCODE_0:
                      Log.v(TAG, "Keycode_0");
                      return true;
                      //break;
  
                  case KeyEvent.KEYCODE_1:
                      Log.v(TAG, "Keycode_1");
                      return true;
                      //break;
                  case KeyEvent.KEYCODE_D:
                      Log.v(TAG, "Keycode_D");
                      return true;
                      //break;
                  case KeyEvent.KEYCODE_2:
                      Log.v(TAG, "Keycode_2");
                      return true;
                      //break;
                  case KeyEvent.KEYCODE_TAB:
                      Log.v(TAG, "Keycode_TAB");
                      return true;
                      //break;
                  case KeyEvent.KEYCODE_DEL:
                      Log.v(TAG, "Keycode_DEL");
                      return true;
                      //break;
                  case KeyEvent.KEYCODE_COMMA:
                      Log.v(TAG, "Keycode_COMMA");
                      return true;
                      //break;
                  case KeyEvent.KEYCODE_ENTER:
                      Log.v(TAG, "KEYCODE_ENTER");
                      i=KeyEvent.KEYCODE_ENTER;
                      Log.v(TAG, "KEYCODE_ENTER"+i);
                      return true;
                      //break;
                 case KeyEvent.KEYCODE_SHIFT_LEFT:
                      Log.v(TAG, "KEYCODE_SHIFT_LEFT"+KeyEvent.KEYCODE_SHIFT_LEFT);
                      return true;
                      //break;
                  case KeyEvent.KEYCODE_SHIFT_RIGHT:
                      Log.v(TAG, "KEYCODE_SHIFT_RIGHT"+KeyEvent.KEYCODE_SHIFT_RIGHT);
                      return true;
                      //break;
                  case KeyEvent.KEYCODE_SPACE:
                      Log.v(TAG, "KEYCODE_SPACE"+KeyEvent.KEYCODE_SPACE);
                      return true;
                      //break;
                  default:
                      break;
              }
              return false;
          }
      });
  </code></pre>
  
  <p>but it is working only for <code>enter</code> and <code>delete</code> keys. For the rest of the keys, it is not working. I wanted it for <code>shift</code> and <code>caps lock</code> keys.</p>