-
Notifications
You must be signed in to change notification settings - Fork 0
/
screenshot.py
executable file
·71 lines (49 loc) · 1.65 KB
/
screenshot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/env monkeyrunner
# Imports the monkeyrunner modules used by this program
from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice
from time import sleep
import os, sys
# ALL VARS, PARAMS and OPTIONS INITIALIZATION
IMG_PATH = None
RECT = None
# PARAMS AND OPTIONS PARSE
# there is no argparse :(
# ALL VARS, PARAMS and OPTIONS TREATMENTS
if len(sys.argv) == 2:
IMG_PATH = sys.argv[1]
RECT = None
elif len(sys.argv) == 6:
IMG_PATH = sys.argv[1]
RECT = tuple([ int(x) for x in sys.argv[2:] ])
else:
print("usage: screenshot PATH [ X Y WIDTH HEIGHT ]\n")
sys.exit(1)
# SCRIPT STARTS HERE
try:
# Connects to the current device, returning a MonkeyDevice object
device = MonkeyRunner.waitForConnection()
# Takes a screenshot
result = device.takeSnapshot()
# getting a sub image from snapshot?
if RECT:
result = result.getSubImage(RECT)
print(IMG_PATH)
# Writes the screenshot to a file
result.writeToFile(IMG_PATH,'png')
except KeyboardInterrupt:
# USE KEYBOARD INTERRUPT TO TREAT ^C
sys.exit("{0}Interrupted by user...{1}".format(bcolors.WARNING, bcolors.ENDC))
# sets a variable with the package's internal name
#package = 'com.example.testpixel'
# sets a variable with the name of an Activity in the package
#activity = 'com.example.testpixel.MainActivity'
# sets the name of the component to start
#runComponent = package + '/' + activity
#device.touch(274,470,MonkeyDevice.DOWN_AND_UP)
#sleep(0.05)
#device.drag((100,500),(100,750),2.0,50)
#sleep(2.0)
# Runs the component
#device.startActivity(component=runComponent)
# Presses the Menu button
# device.press('KEYCODE_MENU', MonkeyDevice.DOWN_AND_UP)