How to press two physical android keys in appium

I am trying to take a screenshot using physical buttons, volume up and power button pressed together, please help me implementing the same

is there any option to do it?

For android use https://stackoverflow.com/questions/24070041/send-multiple-same-keyevents-to-the-adb-shell/24070290#24070290

Thank you,
but unfortunately, I wasn’t able to take a screenshot with that method.
Is that possible to press the volume up and power buttons together, and not one after the other?

have you tried with

public void screenshot() {
      driver.pressKey(new KeyEvent()
    	      .withKey(AndroidKey.VOLUME_DOWN)
    	      .withKey(AndroidKey.POWER));  	
}
1 Like

Hello, @Giuma. Thank you for your response.

I am currently using Python, and unfortunately, none of the code translations I have tried to your suggestion provided me, have given me the desired result.

You can try to send keys using W3C actions as described in https://appiumpro.com/editions/46-sending-arbitrary-keystrokes-with-the-actions-api

The article contains an example of simultaneous Shift+F depressing

I may be late to the party, but here’s how I did it:
driver.pressKey(new KeyEvent()
.withKey(AndroidKey.SYSRQ));