触摸,轻扫或拖动事件模拟在Android上不工作 [英] Touch, swipe or drag events emulating on Android not working

查看:578
本文介绍了触摸,轻扫或拖动事件模拟在Android上不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

看完帖子后,我想通了,如何模拟触摸事件:

After reading posts I figured out how to emulate a touch event :

亚行外壳输入抽头100 100

adb shell input tap 100 100

我为了看有无绘制安装MagicMarker,似乎什么都没有。

I've installed MagicMarker in order to see if anything is drawn, nothing appears.

我也试图与monkeyrunner / androidViewClient触摸功能:

I've also tried with monkeyrunner/androidViewClient Touch functions :

device.touch(100,100,'DOWN_AND_UP');

device.touch(100 , 100, 'DOWN_AND_UP');

我的整个code为AndroidViewClient:

My whole code for AndroidViewClient :

#! /usr/bin/env python
# -*- coding: utf-8 -*-

import getopt, sys
import os

# Add android to path becayuse it seems to not appear on windows

sys.path.append("D:/Dev/adt-bundle-windows-x86_64-20131030/sdk/tools")
sys.path.append("D:/Dev/adt-bundle-windows-x86_64-20131030/sdk/tools/lib")
sys.path.append("D:/Dev/adt-bundle-windows-x86_64-20131030/sdk/platform-tools")

# PyDev sets PYTHONPATH, use it
try:
    for p in os.environ['PYTHONPATH'].split(':'):
        if not p in sys.path:
            sys.path.append(p)
except:
    pass

try:
    sys.path.append(os.path.join(os.environ['ANDROID_VIEW_CLIENT_HOME'], 'src'))
except:
    pass

from com.dtmilano.android.viewclient import ViewClient, ViewNotFoundException
device, serialno = ViewClient.connectToDeviceOrExit()   
vc = ViewClient(device, serialno)
device.touch(100,100,"DOWN_AND_UP")

我成功地使用设备。preSS(KEY code_MENU,DOWN_AND_UP)或device.takeSnapshot(),我根本不为什么触摸事件不是由我的手机收到理解。

I successfully used device.press("KEYCODE_MENU", "DOWN_AND_UP") or device.takeSnapshot(), I don't understand at all why touch events are not received by my handset.

顺便说一句,我使用的实际设备(一个GS3和GS4无论是在4.3)

By the way, I am using real devices (a GS3 and GS4 both in 4.3)

不要犹豫,问的详细信息。

Do not hesitate to ask further information.

推荐答案

我测试过的 MagicMarker 使用这个简单的 AndroidViewClient 的脚本。
请注意,一些修复了 adbclient.drag()在5.1.1版本中引入的,所以要确保你有最新的版本。

I've tested MagicMarker using this simple AndroidViewClient script. Notice that some fixes to adbclient.drag() were introduced in version 5.1.1 so be sure you have the latest version.

#! /usr/bin/env python
# -*- coding: utf-8 -*-
'''
Copyright (C) 2014  Diego Torres Milano
'''

__requires__ = ["androidviewclient >= 5.1.1"]
import pkg_resources
from com.dtmilano.android.adb.adbclient import AdbClient

AdbClient(serialno='.*').drag((100, 100), (400, 400), 1000)

这会产生:

也比你的脚本通知设备 AdbClient 实例。

Also notice than in your script device is the AdbClient instance.

如果您检查多少拖() AdbClient 实施后,你会看到一个使用输入刷卡根据相应的API级别:

If you check how drag() is implemented in AdbClient, you'll see that is using input swipe with parameters according to the corresponding API level:

def drag(self, (x0, y0), (x1, y1), duration, steps=1):
'''
Sends drag event (actually it's using C{input swipe} command.

@param (x0, y0): starting point
@param (x1, y1): ending point
@param duration: duration of the event in ms
@param steps: number of steps (currently ignored by @{input swipe}
'''

version = int(self.getProperty('ro.build.version.sdk'))
if version <= 15:
    raise RuntimeError('drag: API <= 15 not supported (version=%d)' % version)
elif version <= 17:
    self.shell('input swipe %d %d %d %d' % (x0, y0, x1, y1))
else:
    self.shell('input swipe %d %d %d %d %d' % (x0, y0, x1, y1, duration))

这篇关于触摸,轻扫或拖动事件模拟在Android上不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆