How to enter OK key using adb shell input text?

I can enter text into the dialog with adb shell input text "blahblah"just fine. The text appears and ... sits there.

I can send a click on the OK buttons so that the text actually takes effect in any dialogue I entered it into - if I guess the screen orientation to the right, adapt to the current resolution, adapt to the current keyboard option and soon. Awfully awkward.

Is there some kind of magic symbol or key code or some other neat way to make the shell execute the equivalent of clicking OK?

example

In the above screenshot, this is a green ->|  icon in the lower right corner. Sometimes this changes using the exact field, but the meaning is always the same: close the keyboard and continue.

+4
source share
3 answers

I believe what you are looking for adb shell input keyevent 66.
keyeventused to press the keys of the virtual keyboard, and code 66 for the key ENTER.
You can find a list of codes here .

EDIT The mapping between keys and codes can be found in /system/usr/keylayout/qwerty.kl. You can make adb shell cat /system/usr/keylayout/qwerty.kland see the codes you need.

+8
source

You can use AndroidViewClient / culebra and forget about orientation, different screen sizes, etc.

As an example, suppose we want to enter text and click OK in this dialog (part of Api Demos)

enter image description here

just run

culebra -uGo myscript.py

, , "", script

#! /usr/bin/env python
# -*- coding: utf-8 -*-
'''
Copyright (C) 2013-2016  Diego Torres Milano
Created on 2016-06-10 by Culebra v11.5.8
                      __    __    __    __
                     /  \  /  \  /  \  /  \ 
____________________/  __\/  __\/  __\/  __\_____________________________
___________________/  /__/  /__/  /__/  /________________________________
                   | / \   / \   / \   / \   \___
                   |/   \_/   \_/   \_/   \    o \ 
                                           \_____/--<
@author: Diego Torres Milano
@author: Jennifer E. Swofford (ascii art snake)
'''


import re
import sys
import os


try:
    sys.path.insert(0, os.path.join(os.environ['ANDROID_VIEW_CLIENT_HOME'], 'src'))
except:
    pass

from com.dtmilano.android.viewclient import ViewClient

TAG = 'CULEBRA'

_s = 5
_v = '--verbose' in sys.argv


kwargs1 = {'ignoreversioncheck': False, 'verbose': False, 'ignoresecuredevice': False}
device, serialno = ViewClient.connectToDeviceOrExit(**kwargs1)
kwargs2 = {'forceviewserveruse': False, 'useuiautomatorhelper': False, 'ignoreuiautomatorkilled': True, 'autodump': False, 'startviewserver': True, 'compresseddump': True}
vc = ViewClient(device, serialno, **kwargs2)
#vc.dump(window='-1') # FIXME: seems not needed

vc.dump(window=-1)
vc.findViewByIdOrRaise("com.example.android.apis:id/username_edit").setText(u"hello culebra!")
vc.sleep(_s)
vc.dump(window=-1)
vc.findViewWithTextOrRaise(u'OK').touch()

hello culebra! . script .

CulebraTester

CulebraTester - culebra , . -, , culebra.dtmilano.com ( ).

- , .

enter image description here

, A, b, c Next ( ).

/**
 * @@Test comment here@@
 *
 * @throws Exception
 */
@Test
public void culebraGeneratedTest() throws Exception {
    mDevice.findObject(By.clazz(Pattern.compile(".*")).desc("A").pkg("com.android.inputmethod.latin")).clickAndWait(Until.newWindow(), DEFAULT_TIMEOUT);
    mDevice.findObject(By.clazz(Pattern.compile(".*")).desc("b").pkg("com.android.inputmethod.latin")).clickAndWait(Until.newWindow(), DEFAULT_TIMEOUT);
    mDevice.findObject(By.clazz(Pattern.compile(".*")).desc("c").pkg("com.android.inputmethod.latin")).clickAndWait(Until.newWindow(), DEFAULT_TIMEOUT);
    mDevice.findObject(By.clazz(Pattern.compile(".*")).desc("Next").pkg("com.android.inputmethod.latin")).clickAndWait(Until.newWindow(), DEFAULT_TIMEOUT);
}

, UiAutomator.

, ""

enter image description here

+2

The easiest way is to use UiAutomator, but the method below is simple, will this help? If your device is the same, try Android Record N Play . This will record the screen, and you can play later. In addition, you save the shell script for your actions. If you want to play (ui-actions) regardless of the instrument, first record using the instrument and simply call adb shell sh script_nameto play.

-1
source

All Articles