public void simulateKeyPress(final int keyCode, final boolean advanceTime) {
   onPress(keyCode);
   Robolectric.flushForegroundThreadScheduler();
   final AnyKeyboard keyboard = getCurrentKeyboard();
   Assert.assertNotNull(keyboard);
   Keyboard.Key key = null;
   for (Keyboard.Key aKey : keyboard.getKeys()) {
     if (aKey.getPrimaryCode() == keyCode) {
       key = aKey;
       break;
     }
   }
   if (key == null) {
     onKey(keyCode, null, 0, new int[0], true);
   } else {
     onKey(keyCode, key, 0, keyboard.getNearestKeys(key.x + 5, key.y + 5), true);
   }
   Robolectric.flushForegroundThreadScheduler();
   if (advanceTime) ShadowSystemClock.sleep(25);
   onRelease(keyCode);
   Robolectric.flushForegroundThreadScheduler();
 }
 public void simulateTextTyping(
     final String text, final boolean advanceTime, final boolean asDiscreteKeys) {
   if (asDiscreteKeys) {
     for (char key : text.toCharArray()) {
       simulateKeyPress(key, advanceTime);
       updateInputConnection(key);
     }
   } else {
     onText(null, text);
     Robolectric.flushForegroundThreadScheduler();
     if (advanceTime) ShadowSystemClock.sleep(25);
   }
 }