title: Send a key combination (meta key and keycode) via the Android API
body: <p>I can't figure out how to send a combination of a meta key (e.g. CTRL) and a keycode (e.g. for RETURN) with Android (I am using API level 11 = version 3.0).</p>
  
  <p>The documentation of the class <a href="http://developer.android.com/reference/android/view/KeyEvent.html" rel="noreferrer"><em>KeyEvent</em></a> mentions constants like <em>META_CTRL_ON</em> and also supports keycode constants (e.g. <em>KEYCODE_CTRL_LEFT</em>) for meta keys.</p>
  
  <p>I am using the <a href="http://unixpapa.com/js/testkey.html" rel="noreferrer">Javascript Key Event Tester</a> to test the output that is generated by my Input Method Editor (IME). BTW, my goal is to develop a software keyboard.</p>
  
  <p>If I understand the documentation correct, it would be sufficient to execute the following code to send the CTRL key <strong>only</strong>:</p>
  
  <pre><code>this.sendDownUpKeyEvents(KeyEvent.KEYCODE_CTRL_RIGHT);
  </code></pre>
  
  <p>But when this is executed against the Javascript Key Event Tester (see above), nothing happens.</p>
  
  <p>So I need to get a clue how to send meta keys only <strong>and</strong> to send meta keys in combination with another key. I also tried the following to send SHIFT+ENTER (a concrete example):</p>
  
  <pre><code>private void _sendShiftEnter() {
      this.sendDownKeyEvent(KeyEvent.KEYCODE_SHIFT_LEFT);
      final long eventTime = SystemClock.uptimeMillis();
      this.getCurrentInputConnection().sendKeyEvent(
          new KeyEvent(
              eventTime, // The time (in uptimeMillis()) at which this key code originally went down.
              eventTime, // The time (in uptimeMillis()) at which this event happened.
              KeyEvent.ACTION_DOWN, // Action code: either ACTION_DOWN, ACTION_UP, or ACTION_MULTIPLE.
              KeyEvent.KEYCODE_ENTER, // The key code.
              0, // A repeat count for down events (&gt; 0 if this is after the initial down) or event count for multiple events.
              KeyEvent.META_SHIFT_ON, // Flags indicating which meta keys are currently pressed.
              0, // The device ID that generated the key event.
              0, // Raw device scan code of the event.
              KeyEvent.FLAG_SOFT_KEYBOARD | KeyEvent.FLAG_KEEP_TOUCH_MODE, // The flags for this key event.
              InputDevice.SOURCE_KEYBOARD // The input source such as SOURCE_KEYBOARD.
          )
      );
  }
  </code></pre>
  
  <p>The same problem as above occurs here, too: The only recognized key is ENTER.</p>
  
  <p>I already searched the Internet for several hours for examples, how to use the <em>KeyEvent</em> class with meta keys and/or key combinations, but couldn't find at least one example of code.</p>
  
  <p>So, in conclusion: Has anyone experience with the <em>KeyEvent</em> class and can demonstrate me how to send a simple combination of keys (e.g. SHIFT+ENTER) via the Android API?</p>
  
  <p>Thank you in advance!</p>