Giter Site home page Giter Site logo

Comments (5)

Hoaliti avatar Hoaliti commented on July 28, 2024

目前已知的实现方法是在InstrumentationInput里的input里
mInst.sendKeyDownUpSync( KeyEvent.KEYCODE_B );
就是输入一个B

from robothelper.

Jinnrry avatar Jinnrry commented on July 28, 2024

有两种思路,1.把文字写入剪切板,然后模拟按下.ctal+v

第二种是自己实现一个输入法,向自己的输入法发送数据,然后输入法执行输入

from robothelper.

chongkaechin avatar chongkaechin commented on July 28, 2024

建议进入到instrumentation.java里面去看看,里面还有其他函数应该可以试试看,比如:

/////////////////////////////////////////////////////////////////////////////////////////////////

/**
* Sends the key events corresponding to the text to the app being
* instrumented.
*
* @param text The text to be sent.
*/
public void sendStringSync(String text) {
if (text == null) {
return;
}
KeyCharacterMap keyCharacterMap = KeyCharacterMap.load(KeyCharacterMap.VIRTUAL_KEYBOARD);

    KeyEvent[] events = keyCharacterMap.getEvents(text.toCharArray());

    if (events != null) {
        for (int i = 0; i < events.length; i++) {
            // We have to change the time of an event before injecting it because
            // all KeyEvents returned by KeyCharacterMap.getEvents() have the same
            // time stamp and the system rejects too old events. Hence, it is
            // possible for an event to become stale before it is injected if it
            // takes too long to inject the preceding ones.
            sendKeySync(KeyEvent.changeTimeRepeat(events[i], SystemClock.uptimeMillis(), 0));
        }
    }
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////

/**
* Higher-level method for sending both the down and up key events for a
* particular character key code. Equivalent to creating both KeyEvent
* objects by hand and calling {@link #sendKeySync}. The event appears
* as if it came from keyboard 0, the built in one.
*
* @param keyCode The key code of the character to send.
*/
public void sendCharacterSync(int keyCode) {
sendKeySync(new KeyEvent(KeyEvent.ACTION_DOWN, keyCode));
sendKeySync(new KeyEvent(KeyEvent.ACTION_UP, keyCode));
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////

可以的话稍微说一下实际需求,使用场景,我对这些也有点兴趣。

另外楼主提到的KeyEvent里面好像26个字母和数字还有特别的按键比如空格好像都有不是吗,所以是那里让你觉得需要改进呢

希望我的小小意见对你有帮助

from robothelper.

Jinnrry avatar Jinnrry commented on July 28, 2024

@chongkaechin 如果我没记错的话,instrumentation只能输入键盘上的值,如果需要输入中文的话还是得走剪切板和输入法。

突然想到,还有一种可以使用shell执行input命令,input是android的一个debug命令,这个好像可以输入中文

from robothelper.

chongkaechin avatar chongkaechin commented on July 28, 2024

原来如此,学习了。

from robothelper.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.