5

After SDK tool upgrade to revision 12, When I connect to monkeyrunner and use press method like device.press('KEYCODE_HOME','DOWN') Will get error msg

Traceback(most recent call last): File "", line 1, in TypeError:press:The 3rd argument is required.

But I checkde sdk doc that press only contain two argument. is it problem caused by new version SDK tool.

Nancy
  • 51
  • 2
  • I see the same error. And checking the sources it seems indeed that only 2 are required. Very strange. – mxk Aug 15 '11 at 20:07
  • Looks like a bug in monkeyrunner. Just add a blank String as a third argument, and it'll work. – mxk Aug 15 '11 at 20:11

4 Answers4

3

To press a key using monkey runner you need to use something like device.press('KEYCODE_HOME',MonkeyDevice.DOWN_AND_UP) you shouldn't need to add a 3rd argument.

Perhaps your issue was that you were using 'DOWN' instead of MonkeyDevice.DOWN

n8schloss
  • 2,723
  • 2
  • 19
  • 27
  • got the same problem, at 2.3.3 – atian25 Jul 29 '11 at 09:20
  • Take a look at the monkeyrunner device source code at http://android.git.kernel.org/?p=platform/sdk.git;a=blob;f=monkeyrunner/src/com/android/monkeyrunner/MonkeyDevice.java based on what I can tell it seems to say that press only needs 2 arguments. But perhaps it might be helpful to find whats wrong. – n8schloss Jul 29 '11 at 18:02
2

Actually the third argument is also a string indicating the press type. It is a constant in MonkeyDevice: DOWN, UP and DOWN_AND_UP

If you do not want to import MonkeyDevice to only use it on this, the correct string which would be used in Monkeyrunner should be 'down', 'up' and 'downAndUp'.

They are defined in enum class ChimpChat.TouchPressType. Here below is its partial source code:

public enum TouchPressType {
    DOWN("down"), UP("up"), DOWN_AND_UP("downAndUp");
...
}
Xiao
  • 12,235
  • 2
  • 29
  • 36
1

To press a key using monkey runner you need to use something like device.press('KEYCODE_HOME','DOWN',' ') you didn't get the any error.

The 3rd argument will be blank here.

Android Boy
  • 4,335
  • 6
  • 30
  • 58
0

You need to add MonkeyDevice

For example a paste command would look like this.

device.press('KEYCODE_PASTE',MonkeyDevice.DOWN)
Jason Waltz
  • 435
  • 2
  • 10