0

I am trying to do some auto testing and I need to trigger a long press of a key using adb command from my PC. For example, a long press home button would bring up the lates used apps. I found that key event #3 is for home key. But I could not figure out how to trigger a long press of the home button. Some post here suggest using sleep command. But it does not work for me, it always trigger the single click event and then go to sleep. It is not doing a long press action. Please help.

What I tried is: adb shell input keyevent 3 adb shell sleep 2

I am just using home key as an example. It can be any key on an Android device, for example, the dpad key. back key, etc.

Safecoder
  • 1,035
  • 2
  • 17
  • 32

2 Answers2

-1

It's Not Possible as per i have R&D And this reference link.

overriding the Home Key Long press in a category.HOME activity

Community
  • 1
  • 1
Chintan Khetiya
  • 15,962
  • 9
  • 47
  • 85
  • thank you for the quick reply! Sorry I was not very clear in my op. I am looking for triggering an event using adb shell command, not in an app. It is for auto testing purpose. And it does not have to be home key. I am just using it as an example. – Safecoder Nov 03 '12 at 05:29
  • what is your actual concept of this task >? – Chintan Khetiya Nov 03 '12 at 05:38
  • I am doing a automatic testing for some apps we developed. One action we would like to test is a long press of a selection. I am actually using dpad to navigate the UI component. I can use dpad center to do click, but I can't find a way to do long press. In my OP, I am trying to make it more general so I used home key as an example. – Safecoder Nov 03 '12 at 05:42
-2

sleep did not work for you because the input keyevent command sends both key down and key up event before it completes. To properly emulate the "long" press with sleep you need to send separate event for down and up and use sleep in between. There are plenty of answered questions about sendevent usage here on SO.

Alex P.
  • 30,437
  • 17
  • 118
  • 169