利用monkeyrunner给Android屏幕连续截图的小程序

#!/home/arcticant/android-sdks/tools/monkeyrunner
from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice

"""
enter Ctrl+c to end
"""

def androidshot():
    #set the  interval between two screenshot
    sleeptime = 3       

    #connect device 
    print "start ..."
    device = MonkeyRunner.waitForConnection()  

    #begin to take snapshot
    i = 0;
    while i < 100:

    result = device.takeSnapshot()
    filename = str(i) + ".png"
    print filename
    result.writeToFile(filename, 'png')
    MonkeyRunner.sleep(sleeptime)
    i = i + 1

if __name__ == '__main__':
    androidshot()

 

需要monkeyrunner才能运行此脚本

一般android-sdks文件夹下有monkeyrunner
没有写结束代码, ubuntu下直接Ctrl+c结束程序

注意:运行此脚本后最好先保存好此次的截图,第二次运行会覆盖第一次生成的结果。

posted @ 2012-11-16 14:46  登山者  阅读(297)  评论(0编辑  收藏  举报