2

Using adb shell input text <String> or adb shell input keyevent <KEYCODE_NAME> works perfectly fine in sending text to the android device, but my issue is speed.

Using something like input keyevent KEYCODE_A KEYCODE_A KEYCODE_SPACE KEYCODE_A KEYCODE_ENTER; will type the text quickly, but separating it into 2 commands will result in a (1 sec) delay between the 2 commands (Much Slower).

Sample Shell Code:

Method 1 (Much faster):

input keyevent KEYCODE_A KEYCODE_A KEYCODE_ENTER KEYCODE_A KEYCODE_A KEYCODE_ENTER;

Method 2:

input keyevent KEYCODE_A KEYCODE_A KEYCODE_ENTER;
input keyevent KEYCODE_A KEYCODE_A KEYCODE_ENTER;

I would like to type a large text as fast as possible, but having a shell script with input keyevent followed by a large combination of KEYCODE_A for instance, will not be executed. (Large Shell Commands are aborted)

What would be the best way to send large text without having long delays?
Would sendevent be faster in sending large text?

Note:

  • The weakness of input text <String> is that it also has a limit to it's size and it can't perform special keyevents inside of it (Like the Back Button or Enter/New Line ).

Thanks in Advance.

SamJ
  • 413
  • 1
  • 4
  • 18
  • `input keyevent $(for i in $(seq 500); do echo 29; done; echo 30)` worked just fine on my device. do you need to inject more than 500 keycodes at once? – Alex P. Oct 18 '16 at 16:01
  • @AlexP. Your method works fine, but the issue is that there will be a 1 sec delay between every command which is the issue i was trying to avoid. – SamJ Oct 18 '16 at 16:04
  • I was not suggesting a solution but rather questioning your use case – Alex P. Oct 18 '16 at 16:15

1 Answers1

3

I realise you are after Android Shell, but I think you have exhausted the options available to you there.

I know of one way that is faster than what you have tried, using Instrumentation:

final Instrumentation mInst = new Instrumentation();

mInst.sendKeySync(new KeyEvent(KeyEvent.ACTION_DOWN, keycode));
mInst.sendKeySync(new KeyEvent(KeyEvent.ACTION_UP, keycode));
Knossos
  • 15,802
  • 10
  • 54
  • 91