Skip to content

Control a real USB-connected iPhone from Linux (no Mac, no paid developer account) and expose it to AI agents as MCP tools

feat(mcp): iphone_tap taps the same point several times with count (#141)

cosine1451bfc324d3
diff --git a/CHANGELOG.md b/CHANGELOG.md
index d433e42..a85b8d3 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -6,6 +6,10 @@ What changed in each release, one line per change. Versions follow [Semantic Ver
## [Unreleased]
+### New
+
+- `iphone_tap` takes `count` (1–10): the taps go in one gesture, about 0.1 s apart, so a double tap or several quick taps work; separate calls are about 0.5 s apart. An older daemon ignores it and taps once.
+
### Improvements
- An action that had to unlock the phone first says so, and how long it took (#135).
diff --git a/CHANGELOG.zh-CN.md b/CHANGELOG.zh-CN.md
index fa578f6..eaf95ee 100644
--- a/CHANGELOG.zh-CN.md
+++ b/CHANGELOG.zh-CN.md
@@ -6,6 +6,10 @@
## [Unreleased]
+### 新功能
+
+- `iphone_tap` 加 `count`(1~10):在一个手势里连点,每下间隔约 0.1 秒,双击、短时间内连点几下的入口都能点到;分开调用每下约隔 0.5 秒。旧版本守护进程不认这个参数,只点一下。
+
### 改进
- 操作前先自动解锁了的话,结果里会说明,并写明用了多久(#135)。
diff --git a/apps/iphone-control/src/viewer.rs b/apps/iphone-control/src/viewer.rs
index 68815be..2b32e31 100644
--- a/apps/iphone-control/src/viewer.rs
+++ b/apps/iphone-control/src/viewer.rs
@@ -1333,7 +1333,7 @@ fn action(name: &str, b: &Value) -> Option<Request> {
let num = |k: &str| b.get(k).and_then(Value::as_f64).filter(|v| v.is_finite());
let text = |k: &str| b.get(k).and_then(Value::as_str).map(str::to_owned);
Some(match name {
- "tap" => Request::Tap { x: num("x")?, y: num("y")? },
+ "tap" => Request::Tap { x: num("x")?, y: num("y")?, count: 1 },
"long_press" => Request::LongPress { x: num("x")?, y: num("y")?, seconds: num("seconds")?.clamp(0.3, 5.0) },
"swipe" => Request::Swipe {
from: (num("x1")?, num("y1")?),
@@ -2010,7 +2010,7 @@ mod tests {
#[test]
fn page_actions_map_to_daemon_requests() {
- assert_eq!(action("tap", &json!({"x": 10.0, "y": 20.5})), Some(Request::Tap { x: 10.0, y: 20.5 }));
+ assert_eq!(action("tap", &json!({"x": 10.0, "y": 20.5})), Some(Request::Tap { x: 10.0, y: 20.5, count: 1 }));
assert_eq!(
action("swipe", &json!({"x1": 1, "y1": 2, "x2": 3, "y2": 4, "seconds": 9})),
Some(Request::Swipe { from: (1.0, 2.0), to: (3.0, 4.0), seconds: 3.0 })
diff --git a/crates/ictl-daemon/src/core.rs b/crates/ictl-daemon/src/core.rs
index 6bc2b5b..06e41de 100644
--- a/crates/ictl-daemon/src/core.rs
+++ b/crates/ictl-daemon/src/core.rs
@@ -1213,7 +1213,7 @@ impl Daemon {
data = Some(crate::protocol::Data::Elements { elements });
text
}),
- Request::Tap { x, y } => self.tap(g, x, y, view).await,
+ Request::Tap { x, y, count } => self.tap(g, x, y, count, view).await,
Request::TapElement { text, index, max_age_ms } => {
self.tap_element(g, &text, index, Duration::from_millis(max_age_ms)).await.map(|(t, missed)| {
outcome.tapped_nothing = missed;
@@ -1691,7 +1691,7 @@ pub(crate) mod tests {
async fn coordinate_from_a_previous_view_is_rejected_before_dispatch() {
let (d, dir) = test_daemon("previous-view");
let ctx = CallCtx { expect_view: Some("old-view".into()), ..Default::default() };
- let r = d.handle(Request::Tap { x: 3.0, y: 4.0 }, Instant::now(), ctx).await;
+ let r = d.handle(Request::Tap { x: 3.0, y: 4.0, count: 1 }, Instant::now(), ctx).await;
assert!(matches!(r, Response::Error { message, retry_as_gesture: false } if message.contains("画面")));
std::fs::remove_dir_all(dir).unwrap();
}
diff --git a/crates/ictl-daemon/src/lib.rs b/crates/ictl-daemon/src/lib.rs
index a1c66f2..48901e1 100644
--- a/crates/ictl-daemon/src/lib.rs
+++ b/crates/ictl-daemon/src/lib.rs
@@ -369,7 +369,7 @@ mod tests {
assert_eq!(events.next().await.unwrap().event, "task");
assert!(protocol::open_task(&socket, "又一个", "test", &[]).await.is_err(), "one at a time");
- let tap = Request::Tap { x: 1.0, y: 2.0 };
+ let tap = Request::Tap { x: 1.0, y: 2.0, count: 1 };
let r = protocol::call(&socket, &tap, None).await.unwrap();
assert!(matches!(&r, Response::Error { message, .. } if message.contains(&opened.id)), "{r:?}");
// the task's own request gets past the task (and then finds no phone in this test)
@@ -420,7 +420,7 @@ mod tests {
br#"{"op":"tap","x":1.0,"y":2.0,"cancel_on_close":true,"expect_udid":"U1","expect_view":"V1","lang":"en"}"#,
)
.unwrap();
- assert_eq!(req, protocol::Request::Tap { x: 1.0, y: 2.0 });
+ assert_eq!(req, protocol::Request::Tap { x: 1.0, y: 2.0, count: 1 });
assert!(cancel);
assert_eq!(expect.expect_udid.as_deref(), Some("U1"));
assert_eq!(expect.expect_view.as_deref(), Some("V1"));
diff --git a/crates/ictl-daemon/src/tasks.rs b/crates/ictl-daemon/src/tasks.rs
index 1d4f02a..510761e 100644
--- a/crates/ictl-daemon/src/tasks.rs
+++ b/crates/ictl-daemon/src/tasks.rs
@@ -1187,7 +1187,7 @@ fn gesture(tool: &str, args: &Value, result: &str) -> Option<Value> {
/// [`gesture`] for a request that no tool call announced
fn request_gesture(req: &Request) -> Option<Value> {
match req {
- Request::Tap { x, y } => Some(json!({"kind": "tap", "x": x, "y": y})),
+ Request::Tap { x, y, .. } => Some(json!({"kind": "tap", "x": x, "y": y})),
Request::LongPress { x, y, .. } => Some(json!({"kind": "long_press", "x": x, "y": y})),
Request::Swipe { from, to, .. } => {
Some(json!({"kind": "swipe", "x": from.0, "y": from.1, "x2": to.0, "y2": to.1}))
@@ -1219,7 +1219,7 @@ mod tests {
}
fn tap() -> Request {
- Request::Tap { x: 1.0, y: 2.0 }
+ Request::Tap { x: 1.0, y: 2.0, count: 1 }
}
async fn admit(ts: &Tasks, req: &Request, token: Option<&str>) -> Result<(Admission, bool), Response> {
diff --git a/crates/ictl-daemon/src/tools/input.rs b/crates/ictl-daemon/src/tools/input.rs
index 64eb36b..bee991e 100644
--- a/crates/ictl-daemon/src/tools/input.rs
+++ b/crates/ictl-daemon/src/tools/input.rs
@@ -1,6 +1,7 @@
//! Acting at a point or on an element: taps, touches, long presses, swipes, typing
use super::*;
+use crate::protocol::MAX_TAP_COUNT;
impl Daemon {
/// A stale pointer must neither unlock nor act on a new display. Unlock can itself
@@ -37,34 +38,57 @@ impl Daemon {
Ok(rotation)
}
- pub(crate) async fn tap(&self, g: &mut Inner, x: f64, y: f64, view: Option<&str>) -> crate::error::Result<String> {
+ /// 点击 `count` 下(1 = 普通点击)。连点时 WDA 发一个手势([`WdaClient::multi_tap`]),HID 在同一个会话里连发
+ pub(crate) async fn tap(
+ &self,
+ g: &mut Inner,
+ x: f64,
+ y: f64,
+ count: u32,
+ view: Option<&str>,
+ ) -> crate::error::Result<String> {
+ if !(1..=MAX_TAP_COUNT).contains(&count) {
+ return Err(ictl_l10n::trf!(
+ "count 要是 1 到 {MAX_TAP_COUNT} 的整数",
+ "count must be a whole number from 1 to {MAX_TAP_COUNT}"
+ )
+ .into());
+ }
self.prepare_coordinates(g, view, true).await?;
let pos = format!("({},{})", fmt_g(x), fmt_g(y));
+ let times = if count > 1 { ictl_l10n::trf!(",连点 {count} 下", ", {count} times") } else { String::new() };
if let Some(w) = self.wda(g) {
// 只有连不上才退到 HID;超时说明请求已发出,再用 HID 做一遍可能点两次
- match w.tap(x, y).await {
- Ok(()) => return Ok(ictl_l10n::trf!("已点击 {pos}", "Tapped {pos}")),
+ let r = if count > 1 { w.multi_tap(x, y, count).await } else { w.tap(x, y).await };
+ match r {
+ Ok(()) => return Ok(ictl_l10n::trf!("已点击 {pos}{times}", "Tapped {pos}{times}")),
Err(WdaError::Unavailable(_)) if view.is_none() => {}
Err(e) => return Err(e.into()),
}
}
// natively HID is the way, not a fallback: the page's view was checked above as through WDA
- if self.native(g) {
- Box::pin(self.native_tap(g, x, y)).await?;
- return Ok(ictl_l10n::trf!("已点击 {pos}", "Tapped {pos}"));
- }
- if view.is_some() {
+ let native = self.native(g);
+ if !native && view.is_some() {
return Err(wda_down(&g.state, g.info.as_ref()).into());
}
let rot = self.hid_touch_rotation(g).await?;
self.hid_do(g, move |h| {
Box::pin(async move {
h.rotation = rot;
- h.tap(x, y).await
+ for i in 0..count {
+ if i > 0 {
+ tokio::time::sleep(Duration::from_millis(ictl_wda::MULTI_TAP_GAP_MS)).await;
+ }
+ h.tap(x, y).await?;
+ }
+ Ok(())
})
})
.await?;
- Ok(ictl_l10n::trf!("已点击 {pos}(经 HID)", "Tapped {pos} (via HID)"))
+ if native {
+ return Ok(ictl_l10n::trf!("已点击 {pos}{times}", "Tapped {pos}{times}"));
+ }
+ Ok(ictl_l10n::trf!("已点击 {pos}{times}(经 HID)", "Tapped {pos}{times} (via HID)"))
}
/// Follow the viewer pointer with one HID report per call. The first event prepares the device.
diff --git a/crates/ictl-daemon/src/tools/mod.rs b/crates/ictl-daemon/src/tools/mod.rs
index a243b6c..a3d2053 100644
--- a/crates/ictl-daemon/src/tools/mod.rs
+++ b/crates/ictl-daemon/src/tools/mod.rs
@@ -551,7 +551,7 @@ mod tests {
g.info = Some(ictl_device::DeviceInfo { product_version: "26.7.3".into(), ..Default::default() });
g.state = crate::machine::DeviceState::WdaStarting { last_error: None };
let down = |e: &str| e.contains("没有 HID 后备路线") || e.contains("no HID fallback");
- let tap = d.tap(&mut g, 20., 50., None).await.unwrap_err().to_string();
+ let tap = d.tap(&mut g, 20., 50., 1, None).await.unwrap_err().to_string();
assert!(down(&tap), "{tap}");
let swipe = d.swipe(&mut g, (20., 50.), (20., 300.), 0.3, None, false).await.unwrap_err().to_string();
assert!(down(&swipe), "{swipe}");
diff --git a/crates/ictl-mcp/src/lib.rs b/crates/ictl-mcp/src/lib.rs
index 2d53ed2..81e1dbd 100644
--- a/crates/ictl-mcp/src/lib.rs
+++ b/crates/ictl-mcp/src/lib.rs
@@ -7,7 +7,7 @@
use std::path::PathBuf;
use std::time::Duration;
-use ictl_protocol::{self as protocol, Request, Response};
+use ictl_protocol::{self as protocol, MAX_TAP_COUNT, Request, Response};
use rmcp::{
ErrorData, RoleServer, ServerHandler, ServiceExt,
model::{
@@ -329,12 +329,20 @@ WDA 不可用时会说明哪些功能受影响(读元素、按名字点击、启
ictl_l10n::tr!("点击屏幕上的一个坐标(单位是点,与 iphone_screenshot 全屏图的像素一致,左上角为原点)。\n\n\
何时用:目标没有文字(图标、图片)、在游戏或地图里,或 iphone_list_elements 里找不到它时。\
带文字的按钮、列表项优先用 iphone_tap_element,界面布局变了也点得准。按住用 iphone_long_press,滚动用 iphone_swipe。\n\n\
-行为:单指按下约 0.05 秒后抬起,点一次。不检查坐标上是什么,点之前先截图确认位置。\
-WDA 不可用时改用 CoreDevice HID(iOS 27 起;结果里注明「经 HID」)。", "Tap a point on the screen (in points, the same as the pixels of a full-screen iphone_screenshot, origin at the top left).\n\nWhen to use: the target has no text (icon, image), is in a game or map, or can't be found with iphone_list_elements. For buttons and list items with text prefer iphone_tap_element, which keeps working when the layout changes. Use iphone_long_press to hold and iphone_swipe to scroll.\n\nBehavior: one finger down for about 0.05 s, then up; a single tap. It doesn't check what is at that point, so look at a screenshot first. If WDA is unavailable it uses CoreDevice HID instead (iOS 27+; the result says “via HID”)."),
+行为:单指按下约 0.05 秒后抬起,点一次(count 大于 1 时在同一点连点)。不检查坐标上是什么,点之前先截图确认位置。\
+WDA 不可用时改用 CoreDevice HID(iOS 27 起;结果里注明「经 HID」)。", "Tap a point on the screen (in points, the same as the pixels of a full-screen iphone_screenshot, origin at the top left).\n\nWhen to use: the target has no text (icon, image), is in a game or map, or can't be found with iphone_list_elements. For buttons and list items with text prefer iphone_tap_element, which keeps working when the layout changes. Use iphone_long_press to hold and iphone_swipe to scroll.\n\nBehavior: one finger down for about 0.05 s, then up; a single tap (several at the same point with count above 1). It doesn't check what is at that point, so look at a screenshot first. If WDA is unavailable it uses CoreDevice HID instead (iOS 27+; the result says “via HID”)."),
ictl_l10n::tr!("已点击 (120,300)", "Tapped (120,300)"),
true,
),
- schema(with_then(json!({"x": num(ictl_l10n::tr!("x(点)", "x (points)")), "y": num(ictl_l10n::tr!("y(点)", "y (points)"))})), &["x", "y"]),
+ schema(
+ with_then(json!({
+ "x": num(ictl_l10n::tr!("x(点)", "x (points)")),
+ "y": num(ictl_l10n::tr!("y(点)", "y (points)")),
+ "count": {"type": "integer", "default": 1, "minimum": 1, "maximum": MAX_TAP_COUNT,
+ "description": ictl_l10n::tr!("在这一点连点几下,一个手势里点完(每下间隔约 0.1 秒):2 是双击;也用于要在短时间内连点几下的入口。分开调用赶不上这类时间窗", "how many times to tap this point, all in one gesture (about 0.1 s apart): 2 is a double tap; also for entries that need several taps in a short time, which separate calls are too slow for")}
+ })),
+ &["x", "y"],
+ ),
acting(ictl_l10n::tr!("点击坐标", "Tap point"), true, false),
),
t(
@@ -604,6 +612,16 @@ impl Args<'_> {
}),
}
}
+ /// 连点次数:不给是 1,给了要是 1 到 [`MAX_TAP_COUNT`] 的整数
+ fn count(&self, k: &str) -> Result<u32, String> {
+ match self.u_or(k, 1)? {
+ n @ 1.. if n <= MAX_TAP_COUNT as usize => Ok(n as u32),
+ _ => Err(ictl_l10n::trf!(
+ "参数 {k} 要是 1 到 {MAX_TAP_COUNT} 的整数",
+ "parameter {k} must be a whole number from 1 to {MAX_TAP_COUNT}"
+ )),
+ }
+ }
fn b_or(&self, k: &str, d: bool) -> Result<bool, String> {
match self.get(k) {
None => Ok(d),
@@ -641,7 +659,7 @@ pub fn to_request(name: &str, args: &Map<String, Value>) -> Result<Request, Stri
max_age_ms: 0,
keep_locked: false,
},
- "iphone_tap" => Request::Tap { x: a.f("x")?, y: a.f("y")? },
+ "iphone_tap" => Request::Tap { x: a.f("x")?, y: a.f("y")?, count: a.count("count")? },
"iphone_tap_element" => Request::TapElement { text: a.s("text")?, index: a.u_or("index", 0)?, max_age_ms: 0 },
"iphone_long_press" => Request::LongPress { x: a.f("x")?, y: a.f("y")?, seconds: a.f_or("seconds", 1.0)? },
"iphone_swipe" => Request::Swipe {
@@ -1203,6 +1221,21 @@ mod tests {
with_lang(Lang::Zh, || assert!(has_cjk(instructions())));
}
+ /// iphone_tap 不带 count 是点一下;count 要是 1 到 MAX_TAP_COUNT 的整数,给错了报错、不点,不悄悄改成 1
+ #[test]
+ fn tap_count_defaults_to_one_and_rejects_out_of_range() {
+ let tap = |v: Value| to_request("iphone_tap", &args(v));
+ assert_eq!(tap(json!({"x": 1, "y": 2})), Ok(Request::Tap { x: 1.0, y: 2.0, count: 1 }));
+ assert_eq!(tap(json!({"x": 1, "y": 2, "count": 5})), Ok(Request::Tap { x: 1.0, y: 2.0, count: 5 }));
+ for bad in [json!(0), json!(11), json!(2.5), json!(-1), json!("two")] {
+ assert!(tap(json!({"x": 1, "y": 2, "count": bad})).is_err(), "{bad}");
+ }
+ // a batch step takes it too
+ let steps = batch_steps(&args(json!({"steps": [{"tool": "iphone_tap", "x": 1, "y": 2, "count": 2}]})));
+ let req = Request::Tap { x: 1.0, y: 2.0, count: 2 };
+ assert_eq!(steps, Ok(vec![Step::Request { tool: "iphone_tap".into(), req }]));
+ }
+
#[test]
fn alert_check_after_actions_but_not_buttons_or_reads() {
assert!(wants_alert_check(&Request::Swipe { from: (0.0, 0.0), to: (1.0, 1.0), seconds: 0.3 }));
diff --git a/crates/ictl-protocol/src/lib.rs b/crates/ictl-protocol/src/lib.rs
index b9fe2e6..bde4bf9 100644
--- a/crates/ictl-protocol/src/lib.rs
+++ b/crates/ictl-protocol/src/lib.rs
@@ -43,6 +43,17 @@ pub fn default_socket() -> PathBuf {
}
}
+/// [`Request::Tap`] 一次最多连点几下
+pub const MAX_TAP_COUNT: u32 = 10;
+
+fn one() -> u32 {
+ 1
+}
+
+fn is_one(n: &u32) -> bool {
+ *n == 1
+}
+
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum TouchPhase {
@@ -80,6 +91,9 @@ pub enum Request {
Tap {
x: f64,
y: f64,
+ /// 在这一点连点几下(一个手势),1 = 普通点击。旧版本客户端不带,按 1;为 1 时不写进请求,旧版本守护进程照常认
+ #[serde(default = "one", skip_serializing_if = "is_one")]
+ count: u32,
},
TapElement {
text: String,
@@ -872,6 +886,16 @@ pub async fn task_list(socket: &std::path::Path) -> Result<Vec<TaskInfo>, String
mod tests {
use super::*;
+ /// 不带 count 的点击(旧版本客户端)按 1 下;count 为 1 时不写进请求,旧版本守护进程收到的和以前一样
+ #[test]
+ fn a_tap_without_count_is_one_tap_on_the_wire() {
+ let old: Request = serde_json::from_str(r#"{"op":"tap","x":1.0,"y":2.0}"#).unwrap();
+ assert_eq!(old, Request::Tap { x: 1.0, y: 2.0, count: 1 });
+ assert_eq!(serde_json::to_string(&old).unwrap(), r#"{"op":"tap","x":1.0,"y":2.0}"#);
+ let five = Request::Tap { x: 1.0, y: 2.0, count: 5 };
+ assert_eq!(serde_json::to_string(&five).unwrap(), r#"{"op":"tap","x":1.0,"y":2.0,"count":5}"#);
+ }
+
/// A daemon that is restarting (it left the marker just now) is waited for; one that isn't running is reported
/// at once
#[tokio::test]
diff --git a/crates/ictl-wda/src/client.rs b/crates/ictl-wda/src/client.rs
index f9d8c44..81a48c9 100644
--- a/crates/ictl-wda/src/client.rs
+++ b/crates/ictl-wda/src/client.rs
@@ -46,6 +46,8 @@ impl StallReason {
const SCREEN_RECHECK: Duration = Duration::from_secs(60);
/// 普通点击按下的时长(毫秒)。太短可能不被识别成点击;解锁按键另有自己的时长
const TAP_PRESS_MS: u64 = 50;
+/// 连点时两下之间停多久(毫秒):双击要在约 250 毫秒内,「800 毫秒内点 5 下」要每下不到 160 毫秒
+pub const MULTI_TAP_GAP_MS: u64 = 100;
/// W3C pointer 动作的一步
#[derive(Debug, Clone, Copy, PartialEq)]
@@ -61,6 +63,20 @@ pub fn tap_steps(x: f64, y: f64, press_ms: u64) -> Vec<PointerStep> {
vec![PointerStep::Move { x, y, ms: 0 }, PointerStep::Down, PointerStep::Pause { ms: press_ms }, PointerStep::Up]
}
+/// 同一点连点 `count` 下,两下之间停 `gap_ms`:一个手势,一根手指只移动一次。
+/// 一根手指在同一个手势里移到别的点再按,iPhone 17(iOS 26.5.2)上每下都被识别两次(数字键盘上点 7 个键输出 14 位),
+/// 所以这里只点一个点
+pub fn multi_tap_steps(x: f64, y: f64, count: u32, press_ms: u64, gap_ms: u64) -> Vec<PointerStep> {
+ let mut steps = vec![PointerStep::Move { x, y, ms: 0 }];
+ for i in 0..count {
+ if i > 0 {
+ steps.push(PointerStep::Pause { ms: gap_ms });
+ }
+ steps.extend([PointerStep::Down, PointerStep::Pause { ms: press_ms }, PointerStep::Up]);
+ }
+ steps
+}
+
/// 滑动:按下、停 50ms、在 `ms` 毫秒内移到终点、抬起(与 toolkit 一致)
pub fn swipe_steps(from: (f64, f64), to: (f64, f64), ms: u64) -> Vec<PointerStep> {
vec![
@@ -779,6 +795,13 @@ impl<T: Transport> WdaClient<T> {
self.quick_gesture(&tap_steps(x, y, TAP_PRESS_MS), IdleSettings::NO_COOL_OFF).await
}
+ /// 同一点连点 `count` 下(双击、「短时间内连点 N 下」的隐藏入口),一个 actions 手势,每下之间停
+ /// [`MULTI_TAP_GAP_MS`]。分开点每下都要等界面空闲(约 0.6 秒),`iphone_batch` 连点 5 下约 2.9 秒,赶不上这类入口的时间窗
+ pub async fn multi_tap(&mut self, x: f64, y: f64, count: u32) -> Result<()> {
+ let steps = multi_tap_steps(x, y, count, TAP_PRESS_MS, MULTI_TAP_GAP_MS);
+ self.quick_gesture(&steps, IdleSettings::NO_COOL_OFF).await
+ }
+
/// 长按:按下、停 `seconds` 秒、抬起,一个 actions 手势。`/wda/touchAndHold` 前后都等界面空闲,
/// 真机上主屏长按图标 1.2 秒要约 12 秒才返回。等待设置同 [`Self::tap`]
pub async fn touch_and_hold(&mut self, x: f64, y: f64, seconds: f64) -> Result<()> {
@@ -1237,6 +1260,33 @@ mod tests {
assert_eq!(steps.iter().filter(|s| s["type"] == "pointerDown").count(), 1);
}
+ /// 连点是一个 actions 请求:一根手指只移动一次,在同一点按下抬起 N 次,两下之间停 MULTI_TAP_GAP_MS;
+ /// 5 下在 0.8 秒内点完
+ #[tokio::test]
+ async fn multi_tap_is_one_request_at_one_point() {
+ let ok = r#"{"value":null}"#;
+ let m = Mock::with(&[
+ (200, r#"{"sessionId":"A"}"#),
+ (200, r#"{"value":{"waitForIdleTimeout":10,"animationCoolOffTimeout":2}}"#),
+ (200, ok),
+ (200, ok),
+ (200, ok),
+ ]);
+ let mut c = WdaClient::new(&m);
+ c.multi_tap(10.0, 20.0, 5).await.unwrap();
+ let seen = m.seen.lock().unwrap().clone();
+ let actions: Vec<_> = seen.iter().filter(|s| s.1.ends_with("/actions")).collect();
+ assert_eq!(actions.len(), 1);
+ let body = serde_json::from_str::<Value>(actions[0].2.as_deref().unwrap()).unwrap();
+ let steps = body["actions"][0]["actions"].as_array().unwrap();
+ let count = |t: &str| steps.iter().filter(|s| s["type"] == t).count();
+ assert_eq!((count("pointerMove"), count("pointerDown"), count("pointerUp")), (1, 5, 5));
+ assert_eq!((steps[0]["x"].as_f64(), steps[0]["y"].as_f64()), (Some(10.0), Some(20.0)));
+ let ms: u64 = steps.iter().filter_map(|s| s["duration"].as_u64()).sum();
+ assert_eq!(ms, 5 * TAP_PRESS_MS + 4 * MULTI_TAP_GAP_MS);
+ assert!(ms < 800);
+ }
+
#[tokio::test]
async fn remote_error_keeps_first_line_and_unreachable_maps_to_unavailable() {
let m = Mock::with(&[
diff --git a/crates/ictl-wda/src/lib.rs b/crates/ictl-wda/src/lib.rs
index ede821c..fb5a59b 100644
--- a/crates/ictl-wda/src/lib.rs
+++ b/crates/ictl-wda/src/lib.rs
@@ -9,7 +9,7 @@ pub mod elements;
pub mod http;
pub mod runner;
-pub use client::{IdleSettings, Launch, WdaClient, swipe_steps, tap_steps};
+pub use client::{IdleSettings, Launch, MULTI_TAP_GAP_MS, WdaClient, multi_tap_steps, swipe_steps, tap_steps};
pub use runner::WdaRunner;
#[derive(Debug, thiserror::Error)]
diff --git a/docs/dev/regression-cases.md b/docs/dev/regression-cases.md
index 32dd917..d675515 100644
--- a/docs/dev/regression-cases.md
+++ b/docs/dev/regression-cases.md
@@ -150,3 +150,4 @@
| 144 | 设备闲置时自动锁屏,下一个操作先自动解锁(iPad 经 WDA 约 15 秒,iPhone 原生约 9 秒),结果和事件日志都没说,看着像「切换设备后第一个操作慢」 | 结果第一行(截图在说明里、出错时在报错里)写「手机锁着,先自动解锁了,用时 X 秒」,事件日志记「已自动解锁」 | 单测 `an_unlock_first_is_said_on_the_answers_first_line` + 真机(锁屏后按名字点击、截图,两台设备);真机脚本 `scenarios.py lock` |
| 145 | WDA 的短探测已正常应答或返回远端错误,却不清零超时计数,三个独立慢请求仍会触发重启;连接失败反而清零。日志还把长请求和短探测均未应答写成「连续 3 次」、宣称尚未检查的 `/status` 正常,请求超时本身缺端点日志 | 只有正常响应或远端错误清零,连接失败不清零;连续无应答和长请求后的失败探测分别记录原因及实际次数;超时诊断记录方法、短路径和耗时,不记录查询参数或正文 | 单测 `answered_probe_resets_stall_count_after_each_slow_request`、`connection_error_does_not_reset_unanswered_count`、`long_request_and_failed_probe_keep_the_actual_count_and_reason`、`three_short_unanswered_requests_report_a_consecutive_stall`、`answered_session_delete_does_not_mask_a_failed_probe`、`failed_request_log_keeps_endpoint_and_time_without_query`、`successful_request_log_does_not_include_response_body`;真机:同一 iPad、同一 WDA,把只读业务请求的客户端时限缩短到 20ms,短探测保留 5s,对照修复前后各 3 轮 |
| 146 | App 内浏览器(WebView 在导航栏下面,y≈100)里元素坐标整体偏下一个 WebView 的 y:WKWebView 内部有一层节点报 (0,0)、和 WebView 一样大,被当成小组件、之后的子节点都加上偏移,按文字点击点到下面那一行(Safari 全屏的 WebView 从 0 开始,看不出来) | WebView 和它里面的节点不按小组件的相对坐标处理,用元素树里的屏幕坐标 | 单测 `web_contents_keep_screen_coordinates` + 真机(App 内浏览器页面:元素坐标和截图对上,按文字点击点中) |
+| 147 | 分开点击每下都要等界面空闲(每下约 0.5 秒,`iphone_batch` 连点 5 下约 2.8 秒):双击、要在短时间内连点几下的入口都点不出来(键盘上双击 Shift 只是开了又关,大写锁定没开) | `iphone_tap` 的 `count`:同一点在一个 actions 手势里连点,每下间隔 `MULTI_TAP_GAP_MS`(0.1 秒),一根手指只移动一次(一根手指在一个手势里移到别的点再按,每下会被识别两次);HID 在同一个会话里连发 | 单测 `multi_tap_is_one_request_at_one_point`、`tap_count_defaults_to_one_and_rejects_out_of_range`、`a_tap_without_count_is_one_tap_on_the_wire` + 真机(iPhone 12 mini / iOS 26.4.1:搜索框里 count 2/3/5/10 打出的字数一致;Shift 上 count=2 开大写锁定,分开点两下不开) |
diff --git a/docs/tools.md b/docs/tools.md
index c7ae63c..ee9d36e 100644
--- a/docs/tools.md
+++ b/docs/tools.md
@@ -18,7 +18,7 @@ Coordinates are in **points**, the same unit as the pixels of a full-screen `iph
| Tool | Parameters | Notes |
|---|---|---|
-| `iphone_tap` | `x`, `y` | For targets without text (icons, games, maps); falls back to HID when WDA is down |
+| `iphone_tap` | `x`, `y`, `count` (default 1, max 10) | For targets without text (icons, games, maps); falls back to HID when WDA is down. `count` taps the same point that many times in one gesture, about 0.1 s apart: 2 is a double tap (also turns on Caps Lock on the keyboard's Shift key); for hidden entries that need several taps in a short time, which separate calls or `iphone_batch` are too slow for |
| `iphone_tap_element` | `text`, `index` (default 0) | Exact label or name first, then substring. If the element's center is covered (floating toolbar, keyboard, overlay), taps an uncovered part of it; if it is fully covered, does not tap and says so |
| `iphone_long_press` | `x`, `y`, `seconds` (default 1, max 10) | Holds one finger still, then lifts: context menus, home-screen quick actions, text selection |
| `iphone_swipe` | `from_x`, `from_y`, `to_x`, `to_y`, `seconds` (default 0.3, max 10) | Returns after the list has stopped scrolling (up to 2.5 s). Swipe up (`from_y` > `to_y`) to see content further down |
diff --git a/website/en/guide/tools.md b/website/en/guide/tools.md
index c863000..91fba33 100644
--- a/website/en/guide/tools.md
+++ b/website/en/guide/tools.md
@@ -18,7 +18,7 @@ With [auto-unlock](./auto-unlock) on, `iphone_screenshot`, `iphone_list_elements
| Tool | What it does |
|---|---|
-| `iphone_tap` | Tap coordinates |
+| `iphone_tap` | Tap coordinates; `count` taps the same point several times (double tap, entries that need quick repeated taps) |
| `iphone_tap_element` | Tap by text; if the center is covered by a floating bar or the keyboard it taps a visible part, and if it's fully covered it doesn't tap |
| `iphone_long_press` | Long press; `seconds` defaults to 1, max 10 |
| `iphone_swipe` | Swipe; returns once the list has stopped scrolling. `seconds` defaults to 0.3, max 10 |
diff --git a/website/guide/tools.md b/website/guide/tools.md
index 08bf887..543c9cd 100644
--- a/website/guide/tools.md
+++ b/website/guide/tools.md
@@ -18,7 +18,7 @@ MCP 服务提供 17 个工具,开启[开发者工具](#开发者工具-显式
| 工具 | 作用 |
|---|---|
-| `iphone_tap` | 按坐标点击 |
+| `iphone_tap` | 按坐标点击;`count` 在同一点连点(双击、要短时间内连点几下的入口) |
| `iphone_tap_element` | 按文字点击;中心被悬浮栏、键盘挡住时改点露出来的部分,整个被挡住就不点 |
| `iphone_long_press` | 长按;`seconds` 默认 1,最多 10 |
| `iphone_swipe` | 滑动;列表停稳后才返回。`seconds` 默认 0.3,最多 10 |