public void send(CharSequence text) {
    int currentIndex = 0;
    while (currentIndex < text.length()) {
      char currentCharacter = text.charAt(currentIndex);
      if (AndroidKeys.hasAndroidKeyEvent(currentCharacter)) {
        // The next character is special and must be sent individually
        int keyCode = AndroidKeys.keyCodeFor(currentCharacter);
        if (keyCode == KeyEvent.KEYCODE_HOME) {
          throw new RuntimeException(
              "It is not possible to simulate the HOME key using instrumentation. " +
              "Please use adb, e.g. 'adb shell input keyevent 3'.");
        }
        SelendroidLogger.debug("Send keys, sending special key code");
        instrumentation.sendKeyDownUpSync(keyCode);
        currentIndex++;
      } else {
        // There is at least one "normal" character, that is a character
        // represented by a plain Unicode character that can be sent with
        // sendStringSync. So send as many such consecutive normal characters
        // as possible in a single String.
        int nextSpecialKey = indexOfSpecialKey(text, currentIndex);
        SelendroidLogger.debug("Send keys, sending string");
        instrumentation.sendStringSync(text.subSequence(currentIndex, nextSpecialKey).toString());
        currentIndex = nextSpecialKey;
      }
    }
  }
Sends key events to the {@code Instrumentation}. This method will send a portion of the given
{@code CharSequence} as a single {@code String} if the portion does not contain any special
keys.

@param text the keys to send to the {@code Instrumentation}.
selendroid-server/src/main/java/io/selendroid/server/android/InstrumentedKeySender.java