Code example for Instrumentation

Methods: sendKeySync

0
     * @param test The test case that is being run. 
     */ 
    public static void tapMenuKey(ActivityInstrumentationTestCase test) {
        final Instrumentation inst = test.getInstrumentation();
 
        inst.sendKeySync(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MENU));
        inst.sendKeySync(new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_MENU));
    } 
 
    /** 
     * Simulates chording the menu key. 
     *  
     * @param test The test case that is being run. 
     * @param shortcutKey The shortcut key to tap while chording the menu key. 
     */ 
    public static void chordMenuKey(ActivityInstrumentationTestCase test, char shortcutKey) {
        final Instrumentation inst = test.getInstrumentation();
 
        final KeyEvent pushMenuKey = new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MENU);
        final KeyCharacterMap keyCharMap = KeyCharacterMap.load(pushMenuKey.getDeviceId());