USB HID 接口
说明
本页为 自动化接口 / USB HID 模块,与其它开放接口模块并列;对应脚本 usbHidEvent。
- USB HID 开放接口供第三方语言(Python、易语言、C++ 等)通过 HTTP 控制 iPhone,无需蓝牙板 / OTG 板
- 路径前缀:中控地址,例如
http://127.0.0.1:8019 - 全部为
POST,Content-Type: application/json - 与脚本模块 USB HID 函数(usbHidEvent) 一一对应
- 适配 EC iOS USB 10.7.0+;手机建议 iOS 17+
通用返回
{ "code": 0, "msg": "", "data": ""}| 字段 | 说明 |
|---|---|
| code | 0 成功,其它失败 |
| msg | 失败时的错误信息 |
| data | 部分接口返回业务数据(如剪贴板文本);多数动作接口可为空 |
会话
POST 开启 USB HID 会话
POST /openapi/usbhidSessionStart
对应 usbHidEvent.sessionStart(gate)。会话已存在时会复用。
{ "deviceId": "90e2f3834c0977205e441aa664916a9bdde81e8d", "gate": true}| 参数 | 类型 | 必选 | 说明 |
|---|---|---|---|
| deviceId | string | 是 | 设备 ID |
| gate | boolean | 否 | 是否增强兼容模式,默认 true |
请求示例
import requests
body = { "deviceId": "90e2f3834c0977205e441aa664916a9bdde81e8d", "gate": True}r = requests.post("http://127.0.0.1:8019/openapi/usbhidSessionStart", json=body, timeout=30)print(r.json())const body = { "deviceId": "90e2f3834c0977205e441aa664916a9bdde81e8d", "gate": true};const res = await fetch("http://127.0.0.1:8019/openapi/usbhidSessionStart", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(body),});const data = await res.json();console.log(data);curl -s -X POST "http://127.0.0.1:8019/openapi/usbhidSessionStart" \ -H "Content-Type: application/json" \ -d '{"deviceId":"90e2f3834c0977205e441aa664916a9bdde81e8d","gate":true}'using System.Text;using var http = new HttpClient { Timeout = TimeSpan.FromSeconds(30) };var json = "{\"deviceId\":\"90e2f3834c0977205e441aa664916a9bdde81e8d\",\"gate\":true}";using var content = new StringContent(json, Encoding.UTF8, "application/json");using var res = await http.PostAsync("http://127.0.0.1:8019/openapi/usbhidSessionStart", content);var text = await res.Content.ReadAsStringAsync();Console.WriteLine(text);POST 关闭 USB HID 会话
POST /openapi/usbhidSessionStop
{ "deviceId": "90e2f3834c0977205e441aa664916a9bdde81e8d"}请求示例
import requests
body = { "deviceId": "90e2f3834c0977205e441aa664916a9bdde81e8d"}r = requests.post("http://127.0.0.1:8019/openapi/usbhidSessionStop", json=body, timeout=30)print(r.json())const body = { "deviceId": "90e2f3834c0977205e441aa664916a9bdde81e8d"};const res = await fetch("http://127.0.0.1:8019/openapi/usbhidSessionStop", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(body),});const data = await res.json();console.log(data);curl -s -X POST "http://127.0.0.1:8019/openapi/usbhidSessionStop" \ -H "Content-Type: application/json" \ -d '{"deviceId":"90e2f3834c0977205e441aa664916a9bdde81e8d"}'using System.Text;using var http = new HttpClient { Timeout = TimeSpan.FromSeconds(30) };var json = "{\"deviceId\":\"90e2f3834c0977205e441aa664916a9bdde81e8d\"}";using var content = new StringContent(json, Encoding.UTF8, "application/json");using var res = await http.PostAsync("http://127.0.0.1:8019/openapi/usbhidSessionStop", content);var text = await res.Content.ReadAsStringAsync();Console.WriteLine(text);POST 重建 USB HID 会话
POST /openapi/usbhidSessionRestart
点击无响应时可重建会话(对应投屏右键「重建 USBHID 会话」)。
{ "deviceId": "90e2f3834c0977205e441aa664916a9bdde81e8d", "gate": true}请求示例
import requests
body = { "deviceId": "90e2f3834c0977205e441aa664916a9bdde81e8d", "gate": True}r = requests.post("http://127.0.0.1:8019/openapi/usbhidSessionRestart", json=body, timeout=30)print(r.json())const body = { "deviceId": "90e2f3834c0977205e441aa664916a9bdde81e8d", "gate": true};const res = await fetch("http://127.0.0.1:8019/openapi/usbhidSessionRestart", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(body),});const data = await res.json();console.log(data);curl -s -X POST "http://127.0.0.1:8019/openapi/usbhidSessionRestart" \ -H "Content-Type: application/json" \ -d '{"deviceId":"90e2f3834c0977205e441aa664916a9bdde81e8d","gate":true}'using System.Text;using var http = new HttpClient { Timeout = TimeSpan.FromSeconds(30) };var json = "{\"deviceId\":\"90e2f3834c0977205e441aa664916a9bdde81e8d\",\"gate\":true}";using var content = new StringContent(json, Encoding.UTF8, "application/json");using var res = await http.PostAsync("http://127.0.0.1:8019/openapi/usbhidSessionRestart", content);var text = await res.Content.ReadAsStringAsync();Console.WriteLine(text);屏幕与坐标
POST 设置屏幕尺寸
POST /openapi/usbhidSetScreenSize
按截图/投屏实际分辨率填写。也可用 width / height 代替 w / h。
{ "deviceId": "90e2f3834c0977205e441aa664916a9bdde81e8d", "w": 1170, "h": 2532}| 参数 | 类型 | 必选 | 说明 |
|---|---|---|---|
| deviceId | string | 是 | 设备 ID |
| w / width | number | 是 | 宽 |
| h / height | number | 是 | 高 |
请求示例
import requests
body = { "deviceId": "90e2f3834c0977205e441aa664916a9bdde81e8d", "w": 1170, "h": 2532}r = requests.post("http://127.0.0.1:8019/openapi/usbhidSetScreenSize", json=body, timeout=30)print(r.json())const body = { "deviceId": "90e2f3834c0977205e441aa664916a9bdde81e8d", "w": 1170, "h": 2532};const res = await fetch("http://127.0.0.1:8019/openapi/usbhidSetScreenSize", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(body),});const data = await res.json();console.log(data);curl -s -X POST "http://127.0.0.1:8019/openapi/usbhidSetScreenSize" \ -H "Content-Type: application/json" \ -d '{"deviceId":"90e2f3834c0977205e441aa664916a9bdde81e8d","w":1170,"h":2532}'using System.Text;using var http = new HttpClient { Timeout = TimeSpan.FromSeconds(30) };var json = "{\"deviceId\":\"90e2f3834c0977205e441aa664916a9bdde81e8d\",\"w\":1170,\"h\":2532}";using var content = new StringContent(json, Encoding.UTF8, "application/json");using var res = await http.PostAsync("http://127.0.0.1:8019/openapi/usbhidSetScreenSize", content);var text = await res.Content.ReadAsStringAsync();Console.WriteLine(text);触控
坐标与投屏画面、截图像素坐标一致。
POST 点击
POST /openapi/usbhidClickPoint
{ "deviceId": "90e2f3834c0977205e441aa664916a9bdde81e8d", "x": 200, "y": 400}请求示例
import requests
body = { "deviceId": "90e2f3834c0977205e441aa664916a9bdde81e8d", "x": 200, "y": 400}r = requests.post("http://127.0.0.1:8019/openapi/usbhidClickPoint", json=body, timeout=30)print(r.json())const body = { "deviceId": "90e2f3834c0977205e441aa664916a9bdde81e8d", "x": 200, "y": 400};const res = await fetch("http://127.0.0.1:8019/openapi/usbhidClickPoint", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(body),});const data = await res.json();console.log(data);curl -s -X POST "http://127.0.0.1:8019/openapi/usbhidClickPoint" \ -H "Content-Type: application/json" \ -d '{"deviceId":"90e2f3834c0977205e441aa664916a9bdde81e8d","x":200,"y":400}'using System.Text;using var http = new HttpClient { Timeout = TimeSpan.FromSeconds(30) };var json = "{\"deviceId\":\"90e2f3834c0977205e441aa664916a9bdde81e8d\",\"x\":200,\"y\":400}";using var content = new StringContent(json, Encoding.UTF8, "application/json");using var res = await http.PostAsync("http://127.0.0.1:8019/openapi/usbhidClickPoint", content);var text = await res.Content.ReadAsStringAsync();Console.WriteLine(text);POST 双击
POST /openapi/usbhidDoubleClickPoint
参数同点击:deviceId、x、y。
请求示例
import requests
body = { "deviceId": "90e2f3834c0977205e441aa664916a9bdde81e8d", "x": 200, "y": 400}r = requests.post("http://127.0.0.1:8019/openapi/usbhidDoubleClickPoint", json=body, timeout=30)print(r.json())const body = { "deviceId": "90e2f3834c0977205e441aa664916a9bdde81e8d", "x": 200, "y": 400};const res = await fetch("http://127.0.0.1:8019/openapi/usbhidDoubleClickPoint", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(body),});const data = await res.json();console.log(data);curl -s -X POST "http://127.0.0.1:8019/openapi/usbhidDoubleClickPoint" \ -H "Content-Type: application/json" \ -d '{"deviceId":"90e2f3834c0977205e441aa664916a9bdde81e8d","x":200,"y":400}'using System.Text;using var http = new HttpClient { Timeout = TimeSpan.FromSeconds(30) };var json = "{\"deviceId\":\"90e2f3834c0977205e441aa664916a9bdde81e8d\",\"x\":200,\"y\":400}";using var content = new StringContent(json, Encoding.UTF8, "application/json");using var res = await http.PostAsync("http://127.0.0.1:8019/openapi/usbhidDoubleClickPoint", content);var text = await res.Content.ReadAsStringAsync();Console.WriteLine(text);POST 长按
POST /openapi/usbhidPress
{ "deviceId": "90e2f3834c0977205e441aa664916a9bdde81e8d", "x": 200, "y": 400, "delay": 500}| 参数 | 类型 | 必选 | 说明 |
|---|---|---|---|
| delay | number | 否 | 长按毫秒,默认 500 |
请求示例
import requests
body = { "deviceId": "90e2f3834c0977205e441aa664916a9bdde81e8d", "x": 200, "y": 400, "delay": 500}r = requests.post("http://127.0.0.1:8019/openapi/usbhidPress", json=body, timeout=30)print(r.json())const body = { "deviceId": "90e2f3834c0977205e441aa664916a9bdde81e8d", "x": 200, "y": 400, "delay": 500};const res = await fetch("http://127.0.0.1:8019/openapi/usbhidPress", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(body),});const data = await res.json();console.log(data);curl -s -X POST "http://127.0.0.1:8019/openapi/usbhidPress" \ -H "Content-Type: application/json" \ -d '{"deviceId":"90e2f3834c0977205e441aa664916a9bdde81e8d","x":200,"y":400,"delay":500}'using System.Text;using var http = new HttpClient { Timeout = TimeSpan.FromSeconds(30) };var json = "{\"deviceId\":\"90e2f3834c0977205e441aa664916a9bdde81e8d\",\"x\":200,\"y\":400,\"delay\":500}";using var content = new StringContent(json, Encoding.UTF8, "application/json");using var res = await http.PostAsync("http://127.0.0.1:8019/openapi/usbhidPress", content);var text = await res.Content.ReadAsStringAsync();Console.WriteLine(text);POST 滑动
POST /openapi/usbhidSwipeToPoint
{ "deviceId": "90e2f3834c0977205e441aa664916a9bdde81e8d", "x": 100, "y": 800, "ex": 100, "ey": 200, "duration": 500}| 参数 | 类型 | 必选 | 说明 |
|---|---|---|---|
| x, y | number | 是 | 起点 |
| ex, ey | number | 是 | 终点 |
| duration / delay | number | 否 | 滑动时长毫秒,默认 500 |
请求示例
import requests
body = { "deviceId": "90e2f3834c0977205e441aa664916a9bdde81e8d", "x": 100, "y": 800, "ex": 100, "ey": 200, "duration": 500}r = requests.post("http://127.0.0.1:8019/openapi/usbhidSwipeToPoint", json=body, timeout=30)print(r.json())const body = { "deviceId": "90e2f3834c0977205e441aa664916a9bdde81e8d", "x": 100, "y": 800, "ex": 100, "ey": 200, "duration": 500};const res = await fetch("http://127.0.0.1:8019/openapi/usbhidSwipeToPoint", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(body),});const data = await res.json();console.log(data);curl -s -X POST "http://127.0.0.1:8019/openapi/usbhidSwipeToPoint" \ -H "Content-Type: application/json" \ -d '{"deviceId":"90e2f3834c0977205e441aa664916a9bdde81e8d","x":100,"y":800,"ex":100,"ey":200,"duration":500}'using System.Text;using var http = new HttpClient { Timeout = TimeSpan.FromSeconds(30) };var json = "{\"deviceId\":\"90e2f3834c0977205e441aa664916a9bdde81e8d\",\"x\":100,\"y\":800,\"ex\":100,\"ey\":200,\"duration\":500}";using var content = new StringContent(json, Encoding.UTF8, "application/json");using var res = await http.PostAsync("http://127.0.0.1:8019/openapi/usbhidSwipeToPoint", content);var text = await res.Content.ReadAsStringAsync();Console.WriteLine(text);POST 按下 / 移动 / 抬起
POST /openapi/usbhidTouchDownPOST /openapi/usbhidTouchMovePOST /openapi/usbhidTouchUp
参数均为:deviceId、x、y。
POST /openapi/usbhidTouchDown
请求示例
import requests
body = { "deviceId": "90e2f3834c0977205e441aa664916a9bdde81e8d", "x": 200, "y": 400}r = requests.post("http://127.0.0.1:8019/openapi/usbhidTouchDown", json=body, timeout=30)print(r.json())const body = { "deviceId": "90e2f3834c0977205e441aa664916a9bdde81e8d", "x": 200, "y": 400};const res = await fetch("http://127.0.0.1:8019/openapi/usbhidTouchDown", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(body),});const data = await res.json();console.log(data);curl -s -X POST "http://127.0.0.1:8019/openapi/usbhidTouchDown" \ -H "Content-Type: application/json" \ -d '{"deviceId":"90e2f3834c0977205e441aa664916a9bdde81e8d","x":200,"y":400}'using System.Text;using var http = new HttpClient { Timeout = TimeSpan.FromSeconds(30) };var json = "{\"deviceId\":\"90e2f3834c0977205e441aa664916a9bdde81e8d\",\"x\":200,\"y\":400}";using var content = new StringContent(json, Encoding.UTF8, "application/json");using var res = await http.PostAsync("http://127.0.0.1:8019/openapi/usbhidTouchDown", content);var text = await res.Content.ReadAsStringAsync();Console.WriteLine(text);POST /openapi/usbhidTouchMove
请求示例
import requests
body = { "deviceId": "90e2f3834c0977205e441aa664916a9bdde81e8d", "x": 220, "y": 420}r = requests.post("http://127.0.0.1:8019/openapi/usbhidTouchMove", json=body, timeout=30)print(r.json())const body = { "deviceId": "90e2f3834c0977205e441aa664916a9bdde81e8d", "x": 220, "y": 420};const res = await fetch("http://127.0.0.1:8019/openapi/usbhidTouchMove", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(body),});const data = await res.json();console.log(data);curl -s -X POST "http://127.0.0.1:8019/openapi/usbhidTouchMove" \ -H "Content-Type: application/json" \ -d '{"deviceId":"90e2f3834c0977205e441aa664916a9bdde81e8d","x":220,"y":420}'using System.Text;using var http = new HttpClient { Timeout = TimeSpan.FromSeconds(30) };var json = "{\"deviceId\":\"90e2f3834c0977205e441aa664916a9bdde81e8d\",\"x\":220,\"y\":420}";using var content = new StringContent(json, Encoding.UTF8, "application/json");using var res = await http.PostAsync("http://127.0.0.1:8019/openapi/usbhidTouchMove", content);var text = await res.Content.ReadAsStringAsync();Console.WriteLine(text);POST /openapi/usbhidTouchUp
请求示例
import requests
body = { "deviceId": "90e2f3834c0977205e441aa664916a9bdde81e8d", "x": 220, "y": 420}r = requests.post("http://127.0.0.1:8019/openapi/usbhidTouchUp", json=body, timeout=30)print(r.json())const body = { "deviceId": "90e2f3834c0977205e441aa664916a9bdde81e8d", "x": 220, "y": 420};const res = await fetch("http://127.0.0.1:8019/openapi/usbhidTouchUp", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(body),});const data = await res.json();console.log(data);curl -s -X POST "http://127.0.0.1:8019/openapi/usbhidTouchUp" \ -H "Content-Type: application/json" \ -d '{"deviceId":"90e2f3834c0977205e441aa664916a9bdde81e8d","x":220,"y":420}'using System.Text;using var http = new HttpClient { Timeout = TimeSpan.FromSeconds(30) };var json = "{\"deviceId\":\"90e2f3834c0977205e441aa664916a9bdde81e8d\",\"x\":220,\"y\":420}";using var content = new StringContent(json, Encoding.UTF8, "application/json");using var res = await http.PostAsync("http://127.0.0.1:8019/openapi/usbhidTouchUp", content);var text = await res.Content.ReadAsStringAsync();Console.WriteLine(text);POST 多点触控轨迹
POST /openapi/usbhidMultiTouch
{ "deviceId": "90e2f3834c0977205e441aa664916a9bdde81e8d", "finger1": [ { "action": 0, "x": 100, "y": 500, "delay": 20 }, { "action": 2, "x": 100, "y": 300, "delay": 30 }, { "action": 1, "x": 100, "y": 300, "delay": 20 } ], "timeout": 10000}| 参数 | 类型 | 必选 | 说明 |
|---|---|---|---|
| finger1 / data | array/string | 是 | 触点轨迹;action:0 按下、2 移动、1 抬起 |
| timeout / delay | number | 否 | 总超时毫秒,默认 10000 |
请求示例
import requests
body = { "deviceId": "90e2f3834c0977205e441aa664916a9bdde81e8d", "finger1": [ { "action": 0, "x": 100, "y": 500, "delay": 20 }, { "action": 2, "x": 100, "y": 300, "delay": 30 }, { "action": 1, "x": 100, "y": 300, "delay": 20 } ], "timeout": 10000}r = requests.post("http://127.0.0.1:8019/openapi/usbhidMultiTouch", json=body, timeout=30)print(r.json())const body = { "deviceId": "90e2f3834c0977205e441aa664916a9bdde81e8d", "finger1": [ { "action": 0, "x": 100, "y": 500, "delay": 20 }, { "action": 2, "x": 100, "y": 300, "delay": 30 }, { "action": 1, "x": 100, "y": 300, "delay": 20 } ], "timeout": 10000};const res = await fetch("http://127.0.0.1:8019/openapi/usbhidMultiTouch", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(body),});const data = await res.json();console.log(data);curl -s -X POST "http://127.0.0.1:8019/openapi/usbhidMultiTouch" \ -H "Content-Type: application/json" \ -d '{"deviceId":"90e2f3834c0977205e441aa664916a9bdde81e8d","finger1":[{"action":0,"x":100,"y":500,"delay":20},{"action":2,"x":100,"y":300,"delay":30},{"action":1,"x":100,"y":300,"delay":20}],"timeout":10000}'using System.Text;using var http = new HttpClient { Timeout = TimeSpan.FromSeconds(30) };var json = "{\"deviceId\":\"90e2f3834c0977205e441aa664916a9bdde81e8d\",\"finger1\":[{\"action\":0,\"x\":100,\"y\":500,\"delay\":20},{\"action\":2,\"x\":100,\"y\":300,\"delay\":30},{\"action\":1,\"x\":100,\"y\":300,\"delay\":20}],\"timeout\":10000}";using var content = new StringContent(json, Encoding.UTF8, "application/json");using var res = await http.PostAsync("http://127.0.0.1:8019/openapi/usbhidMultiTouch", content);var text = await res.Content.ReadAsStringAsync();Console.WriteLine(text);输入与按键
POST 粘贴输入
POST /openapi/usbhidInputText
统一剪贴板粘贴,适合中英文。也可用字段 content。
{ "deviceId": "90e2f3834c0977205e441aa664916a9bdde81e8d", "text": "你好"}请求示例
import requests
body = { "deviceId": "90e2f3834c0977205e441aa664916a9bdde81e8d", "text": "你好"}r = requests.post("http://127.0.0.1:8019/openapi/usbhidInputText", json=body, timeout=30)print(r.json())const body = { "deviceId": "90e2f3834c0977205e441aa664916a9bdde81e8d", "text": "你好"};const res = await fetch("http://127.0.0.1:8019/openapi/usbhidInputText", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(body),});const data = await res.json();console.log(data);curl -s -X POST "http://127.0.0.1:8019/openapi/usbhidInputText" \ -H "Content-Type: application/json" \ -d '{"deviceId":"90e2f3834c0977205e441aa664916a9bdde81e8d","text":"你好"}'using System.Text;using var http = new HttpClient { Timeout = TimeSpan.FromSeconds(30) };var json = "{\"deviceId\":\"90e2f3834c0977205e441aa664916a9bdde81e8d\",\"text\":\"你好\"}";using var content = new StringContent(json, Encoding.UTF8, "application/json");using var res = await http.PostAsync("http://127.0.0.1:8019/openapi/usbhidInputText", content);var text = await res.Content.ReadAsStringAsync();Console.WriteLine(text);POST 打字输入
POST /openapi/usbhidTypeText
可打印英文走键盘;含中文、emoji 等自动改粘贴。
{ "deviceId": "90e2f3834c0977205e441aa664916a9bdde81e8d", "text": "hello"}请求示例
import requests
body = { "deviceId": "90e2f3834c0977205e441aa664916a9bdde81e8d", "text": "hello"}r = requests.post("http://127.0.0.1:8019/openapi/usbhidTypeText", json=body, timeout=30)print(r.json())const body = { "deviceId": "90e2f3834c0977205e441aa664916a9bdde81e8d", "text": "hello"};const res = await fetch("http://127.0.0.1:8019/openapi/usbhidTypeText", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(body),});const data = await res.json();console.log(data);curl -s -X POST "http://127.0.0.1:8019/openapi/usbhidTypeText" \ -H "Content-Type: application/json" \ -d '{"deviceId":"90e2f3834c0977205e441aa664916a9bdde81e8d","text":"hello"}'using System.Text;using var http = new HttpClient { Timeout = TimeSpan.FromSeconds(30) };var json = "{\"deviceId\":\"90e2f3834c0977205e441aa664916a9bdde81e8d\",\"text\":\"hello\"}";using var content = new StringContent(json, Encoding.UTF8, "application/json");using var res = await http.PostAsync("http://127.0.0.1:8019/openapi/usbhidTypeText", content);var text = await res.Content.ReadAsStringAsync();Console.WriteLine(text);POST 系统按键
POST /openapi/usbhidSystemKey
{ "deviceId": "90e2f3834c0977205e441aa664916a9bdde81e8d", "key": "home"}| key | 说明 |
|---|---|
| home | 主屏 |
| recents | 多任务 |
| lock | 锁屏 |
请求示例
import requests
body = { "deviceId": "90e2f3834c0977205e441aa664916a9bdde81e8d", "key": "home"}r = requests.post("http://127.0.0.1:8019/openapi/usbhidSystemKey", json=body, timeout=30)print(r.json())const body = { "deviceId": "90e2f3834c0977205e441aa664916a9bdde81e8d", "key": "home"};const res = await fetch("http://127.0.0.1:8019/openapi/usbhidSystemKey", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(body),});const data = await res.json();console.log(data);curl -s -X POST "http://127.0.0.1:8019/openapi/usbhidSystemKey" \ -H "Content-Type: application/json" \ -d '{"deviceId":"90e2f3834c0977205e441aa664916a9bdde81e8d","key":"home"}'using System.Text;using var http = new HttpClient { Timeout = TimeSpan.FromSeconds(30) };var json = "{\"deviceId\":\"90e2f3834c0977205e441aa664916a9bdde81e8d\",\"key\":\"home\"}";using var content = new StringContent(json, Encoding.UTF8, "application/json");using var res = await http.PostAsync("http://127.0.0.1:8019/openapi/usbhidSystemKey", content);var text = await res.Content.ReadAsStringAsync();Console.WriteLine(text);POST 字符按键 / 组合键
POST /openapi/usbhidKeyPressChar
{ "deviceId": "90e2f3834c0977205e441aa664916a9bdde81e8d", "prefix": "gui", "code": "v"}| 参数 | 说明 |
|---|---|
| prefix | 可空:alt / ctrl / gui / shift / r_ctrl / r_shift |
| code | 字符或键名,如 a / enter / BS |
请求示例
import requests
body = { "deviceId": "90e2f3834c0977205e441aa664916a9bdde81e8d", "prefix": "gui", "code": "v"}r = requests.post("http://127.0.0.1:8019/openapi/usbhidKeyPressChar", json=body, timeout=30)print(r.json())const body = { "deviceId": "90e2f3834c0977205e441aa664916a9bdde81e8d", "prefix": "gui", "code": "v"};const res = await fetch("http://127.0.0.1:8019/openapi/usbhidKeyPressChar", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(body),});const data = await res.json();console.log(data);curl -s -X POST "http://127.0.0.1:8019/openapi/usbhidKeyPressChar" \ -H "Content-Type: application/json" \ -d '{"deviceId":"90e2f3834c0977205e441aa664916a9bdde81e8d","prefix":"gui","code":"v"}'using System.Text;using var http = new HttpClient { Timeout = TimeSpan.FromSeconds(30) };var json = "{\"deviceId\":\"90e2f3834c0977205e441aa664916a9bdde81e8d\",\"prefix\":\"gui\",\"code\":\"v\"}";using var content = new StringContent(json, Encoding.UTF8, "application/json");using var res = await http.PostAsync("http://127.0.0.1:8019/openapi/usbhidKeyPressChar", content);var text = await res.Content.ReadAsStringAsync();Console.WriteLine(text);POST 按下单个键 / 抬起
POST /openapi/usbhidKeyPress— body:deviceId、key(或code)POST /openapi/usbhidKeyUp— body:deviceId
POST /openapi/usbhidKeyPress
请求示例
import requests
body = { "deviceId": "90e2f3834c0977205e441aa664916a9bdde81e8d", "key": "enter"}r = requests.post("http://127.0.0.1:8019/openapi/usbhidKeyPress", json=body, timeout=30)print(r.json())const body = { "deviceId": "90e2f3834c0977205e441aa664916a9bdde81e8d", "key": "enter"};const res = await fetch("http://127.0.0.1:8019/openapi/usbhidKeyPress", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(body),});const data = await res.json();console.log(data);curl -s -X POST "http://127.0.0.1:8019/openapi/usbhidKeyPress" \ -H "Content-Type: application/json" \ -d '{"deviceId":"90e2f3834c0977205e441aa664916a9bdde81e8d","key":"enter"}'using System.Text;using var http = new HttpClient { Timeout = TimeSpan.FromSeconds(30) };var json = "{\"deviceId\":\"90e2f3834c0977205e441aa664916a9bdde81e8d\",\"key\":\"enter\"}";using var content = new StringContent(json, Encoding.UTF8, "application/json");using var res = await http.PostAsync("http://127.0.0.1:8019/openapi/usbhidKeyPress", content);var text = await res.Content.ReadAsStringAsync();Console.WriteLine(text);POST /openapi/usbhidKeyUp
请求示例
import requests
body = { "deviceId": "90e2f3834c0977205e441aa664916a9bdde81e8d"}r = requests.post("http://127.0.0.1:8019/openapi/usbhidKeyUp", json=body, timeout=30)print(r.json())const body = { "deviceId": "90e2f3834c0977205e441aa664916a9bdde81e8d"};const res = await fetch("http://127.0.0.1:8019/openapi/usbhidKeyUp", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(body),});const data = await res.json();console.log(data);curl -s -X POST "http://127.0.0.1:8019/openapi/usbhidKeyUp" \ -H "Content-Type: application/json" \ -d '{"deviceId":"90e2f3834c0977205e441aa664916a9bdde81e8d"}'using System.Text;using var http = new HttpClient { Timeout = TimeSpan.FromSeconds(30) };var json = "{\"deviceId\":\"90e2f3834c0977205e441aa664916a9bdde81e8d\"}";using var content = new StringContent(json, Encoding.UTF8, "application/json");using var res = await http.PostAsync("http://127.0.0.1:8019/openapi/usbhidKeyUp", content);var text = await res.Content.ReadAsStringAsync();Console.WriteLine(text);POST 音量 / 静音
仅需 deviceId:
POST /openapi/usbhidVolumeUpPOST /openapi/usbhidVolumeDownPOST /openapi/usbhidMute
POST /openapi/usbhidVolumeUp
请求示例
import requests
body = { "deviceId": "90e2f3834c0977205e441aa664916a9bdde81e8d"}r = requests.post("http://127.0.0.1:8019/openapi/usbhidVolumeUp", json=body, timeout=30)print(r.json())const body = { "deviceId": "90e2f3834c0977205e441aa664916a9bdde81e8d"};const res = await fetch("http://127.0.0.1:8019/openapi/usbhidVolumeUp", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(body),});const data = await res.json();console.log(data);curl -s -X POST "http://127.0.0.1:8019/openapi/usbhidVolumeUp" \ -H "Content-Type: application/json" \ -d '{"deviceId":"90e2f3834c0977205e441aa664916a9bdde81e8d"}'using System.Text;using var http = new HttpClient { Timeout = TimeSpan.FromSeconds(30) };var json = "{\"deviceId\":\"90e2f3834c0977205e441aa664916a9bdde81e8d\"}";using var content = new StringContent(json, Encoding.UTF8, "application/json");using var res = await http.PostAsync("http://127.0.0.1:8019/openapi/usbhidVolumeUp", content);var text = await res.Content.ReadAsStringAsync();Console.WriteLine(text);POST /openapi/usbhidVolumeDown
请求示例
import requests
body = { "deviceId": "90e2f3834c0977205e441aa664916a9bdde81e8d"}r = requests.post("http://127.0.0.1:8019/openapi/usbhidVolumeDown", json=body, timeout=30)print(r.json())const body = { "deviceId": "90e2f3834c0977205e441aa664916a9bdde81e8d"};const res = await fetch("http://127.0.0.1:8019/openapi/usbhidVolumeDown", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(body),});const data = await res.json();console.log(data);curl -s -X POST "http://127.0.0.1:8019/openapi/usbhidVolumeDown" \ -H "Content-Type: application/json" \ -d '{"deviceId":"90e2f3834c0977205e441aa664916a9bdde81e8d"}'using System.Text;using var http = new HttpClient { Timeout = TimeSpan.FromSeconds(30) };var json = "{\"deviceId\":\"90e2f3834c0977205e441aa664916a9bdde81e8d\"}";using var content = new StringContent(json, Encoding.UTF8, "application/json");using var res = await http.PostAsync("http://127.0.0.1:8019/openapi/usbhidVolumeDown", content);var text = await res.Content.ReadAsStringAsync();Console.WriteLine(text);POST /openapi/usbhidMute
请求示例
import requests
body = { "deviceId": "90e2f3834c0977205e441aa664916a9bdde81e8d"}r = requests.post("http://127.0.0.1:8019/openapi/usbhidMute", json=body, timeout=30)print(r.json())const body = { "deviceId": "90e2f3834c0977205e441aa664916a9bdde81e8d"};const res = await fetch("http://127.0.0.1:8019/openapi/usbhidMute", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(body),});const data = await res.json();console.log(data);curl -s -X POST "http://127.0.0.1:8019/openapi/usbhidMute" \ -H "Content-Type: application/json" \ -d '{"deviceId":"90e2f3834c0977205e441aa664916a9bdde81e8d"}'using System.Text;using var http = new HttpClient { Timeout = TimeSpan.FromSeconds(30) };var json = "{\"deviceId\":\"90e2f3834c0977205e441aa664916a9bdde81e8d\"}";using var content = new StringContent(json, Encoding.UTF8, "application/json");using var res = await http.PostAsync("http://127.0.0.1:8019/openapi/usbhidMute", content);var text = await res.Content.ReadAsStringAsync();Console.WriteLine(text);剪贴板
POST 设置剪贴板
POST /openapi/usbhidSetClipboard
{ "deviceId": "90e2f3834c0977205e441aa664916a9bdde81e8d", "text": "剪贴板内容"}请求示例
import requests
body = { "deviceId": "90e2f3834c0977205e441aa664916a9bdde81e8d", "text": "剪贴板内容"}r = requests.post("http://127.0.0.1:8019/openapi/usbhidSetClipboard", json=body, timeout=30)print(r.json())const body = { "deviceId": "90e2f3834c0977205e441aa664916a9bdde81e8d", "text": "剪贴板内容"};const res = await fetch("http://127.0.0.1:8019/openapi/usbhidSetClipboard", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(body),});const data = await res.json();console.log(data);curl -s -X POST "http://127.0.0.1:8019/openapi/usbhidSetClipboard" \ -H "Content-Type: application/json" \ -d '{"deviceId":"90e2f3834c0977205e441aa664916a9bdde81e8d","text":"剪贴板内容"}'using System.Text;using var http = new HttpClient { Timeout = TimeSpan.FromSeconds(30) };var json = "{\"deviceId\":\"90e2f3834c0977205e441aa664916a9bdde81e8d\",\"text\":\"剪贴板内容\"}";using var content = new StringContent(json, Encoding.UTF8, "application/json");using var res = await http.PostAsync("http://127.0.0.1:8019/openapi/usbhidSetClipboard", content);var text = await res.Content.ReadAsStringAsync();Console.WriteLine(text);POST 读取剪贴板
POST /openapi/usbhidGetClipboard
{ "deviceId": "90e2f3834c0977205e441aa664916a9bdde81e8d"}成功时文本在返回的 data 中。
与脚本 / BLE 对照
脚本 usbHidEvent | OpenAPI 接口名 | 说明 |
|---|---|---|
| sessionStart | usbhidSessionStart | 开启会话 |
| sessionStop | usbhidSessionStop | 关闭会话 |
| sessionRestart | usbhidSessionRestart | 重建会话 |
| setScreenSize | usbhidSetScreenSize | 屏幕尺寸 |
| clickPoint | usbhidClickPoint | 点击 |
| press | usbhidPress | 长按 |
| swipeToPoint | usbhidSwipeToPoint | 滑动 |
| typeText / inputText | usbhidTypeText / usbhidInputText | 打字 / 粘贴 |
| … | 见本页各接口 | 其余同名对应 |
请求示例
import requests
body = { "deviceId": "90e2f3834c0977205e441aa664916a9bdde81e8d"}r = requests.post("http://127.0.0.1:8019/openapi/usbhidGetClipboard", json=body, timeout=30)print(r.json())const body = { "deviceId": "90e2f3834c0977205e441aa664916a9bdde81e8d"};const res = await fetch("http://127.0.0.1:8019/openapi/usbhidGetClipboard", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(body),});const data = await res.json();console.log(data);curl -s -X POST "http://127.0.0.1:8019/openapi/usbhidGetClipboard" \ -H "Content-Type: application/json" \ -d '{"deviceId":"90e2f3834c0977205e441aa664916a9bdde81e8d"}'using System.Text;using var http = new HttpClient { Timeout = TimeSpan.FromSeconds(30) };var json = "{\"deviceId\":\"90e2f3834c0977205e441aa664916a9bdde81e8d\"}";using var content = new StringContent(json, Encoding.UTF8, "application/json");using var res = await http.PostAsync("http://127.0.0.1:8019/openapi/usbhidGetClipboard", content);var text = await res.Content.ReadAsStringAsync();Console.WriteLine(text);蓝牙板方案见 自动化 · 蓝牙 BLE;USB HID 不需要 打开串口、配对开发板等步骤。
更多脚本说明:USB HID 函数 · 投屏场景指引