Hi,

I tested this on Nexus S and it worked in the way I expected.  If I specify
DOWN_AND_UP, the screen locks and goes to sleep.  If I specify just DOWN, I
get the Phone options.

I tried with the emulator and saw the same behavior you saw, I'm not sure
why.

Let me try and borrow an Xperia from somebody to reproduce there.

On Thu, Mar 3, 2011 at 5:50 PM, aniruddha dhamal <ani123.dha...@gmail.com>wrote:

> Thanks Bill,
>
> But this code for short press on POWER button isn't working. I tried with
> emulator  (Android 1.6, Android 2.1) and also on Xperia device.  I also
> tried with controlling duration of the press but it opens the Phone Options.
> I wanted to simulate lock screen by pressing on POWER Button.
>
> With this command [ *device.press('KEYCODE_POWER', 'down') *] you can
> open the dialogue box which gives the Phone options (Silent Mode, Airplane
> Mode and Power off).
>
> Is there any other way to simulate the lock screen?
>
> Really Appreciate your help.
>
>
> On Thu, Mar 3, 2011 at 4:30 PM, Bill Napier <nap...@android.com> wrote:
>
>> This worked for me.  It turned off my Nexus S when I tried it.
>>
>> What you were doing was only sending the down part of the DOWN_AND_UP, so
>> it was like you were pressing the POWER button and then never ever taking
>> your finger off of it.
>>
>> If you want even more control over the duration of the press, you can do a
>> DOWN, sleep for a bit, and then do the UP.  DOWN_AND_UP runs the commands
>> with no delay in-between at all (a really short press).
>>
>> ----- code snipped -----
>>
>> from com.android.monkeyrunner import MonkeyRunner as mr
>> from com.android.monkeyrunner import MonkeyDevice
>>
>> device = mr.waitForConnection()
>>
>> device.press("POWER", MonkeyDevice.DOWN_AND_UP)
>>
>>
>> On Mon, Feb 28, 2011 at 11:56 AM, aniruddha dhamal <
>> ani123.dha...@gmail.com> wrote:
>>
>>> I tried to use
>>>
>>> *device.press('KEYCODE_POWER', 'down')*
>>>
>>> but this works for long press on power button.
>>>
>>> Thanks,
>>>
>>>
>>> On Sat, Feb 26, 2011 at 4:01 PM, Andya <ani123.dha...@gmail.com> wrote:
>>>
>>>> Hello guys,
>>>>
>>>> Any help on how to simulate short key press on Power button using
>>>> MonkeyRunner?
>>>>
>>>> I am using the following code but to no avail
>>>>
>>>> device.press('KEYCODE_POWER','DOWN')
>>>>
>>>> Really appreciate!!!
>>>>
>>>> --
>>>> You received this message because you are subscribed to the Google
>>>> Groups "Android Developers" group.
>>>> To post to this group, send email to
>>>> android-developers@googlegroups.com
>>>> To unsubscribe from this group, send email to
>>>> android-developers+unsubscr...@googlegroups.com
>>>> For more options, visit this group at
>>>> http://groups.google.com/group/android-developers?hl=en
>>>
>>>
>>>
>>>
>>> --
>>> Thanks and Regards
>>>
>>> Aniruddha Dhamal
>>> ani123.dha...@gmail.com
>>>
>>> " No matter which direction you start
>>> Its always against the wind coming  back "
>>>
>>>  --
>>> You received this message because you are subscribed to the Google
>>> Groups "Android Developers" group.
>>> To post to this group, send email to android-developers@googlegroups.com
>>> To unsubscribe from this group, send email to
>>> android-developers+unsubscr...@googlegroups.com
>>> For more options, visit this group at
>>> http://groups.google.com/group/android-developers?hl=en
>>>
>>
>>
>
>
> --
> Thanks and Regards
>
> Aniruddha Dhamal
> ani123.dha...@gmail.com
>
> " No matter which direction you start
> Its always against the wind coming  back "
>

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to