USB HID调用api和demo

GoKu
Dec 6, 2024, 4:01:17 PM

function main() {
var usb = new UsbClient();
var b = usb.connect();
console.log('connect:', b);
if (b) {
usbHome(usb);
}
console.log('end')
}

function usbClick(usb, x, y, duration) {
if (null == duration) {
duration = 200
}
usbMouseMove(usb, x, y);
sleep(duration);
usbMouseUp(usb);
}

function usbSwipe(usb, x1, y1, x2, y2, duration) {
if (null == duration) {
duration = 200
}
var cmd = `f${x1},${y1},${x2},${y2},${duration}`;
console.log('cmd:' + cmd)
var ret = usb.send(cmd)
console.log('send ret:', ret)
}

function usbHome(usb) {
usbKeyDown(usb, 135, 40);
sleep(100)
usbKeyUp(usb);
}

function usbBack(usb) {
usbKeyDown(usb, 131, 42);
sleep(100)
usbKeyUp(usb);
}

function usbRecentApps(usb) {
usbKeyDown(usb, 4, 43);
sleep(100)
usbKeyUp(usb);
}

function usbCopy(usb) {
usbKeyDown(usb, 1, 6);
sleep(100)
usbKeyUp(usb);
}

function usbPaste(usb) {
usbKeyDown(usb, 1, 25);
sleep(100)
usbKeyUp(usb);
}

function usbCut(usb) {
usbKeyDown(usb, 1, 27);
sleep(100)
usbKeyUp(usb);
}

function usbSelectAll(usb) {
usbKeyDown(usb, 1, 4);
sleep(100)
usbKeyUp(usb);
}

function usbKeyDown(usb, modifier, keyCode) {
var ret = usb.send(`d${modifier},${keyCode}`)
console.log('send ret:', ret)
}

function usbKeyUp(usb) {
var ret = usb.send('u')
console.log('send ret:', ret)
}

function usbMouseMove(usb, x, y) {
x = parseInt(x * 10000 / rsScreenWidth);
y = parseInt(y * 10000 / rsScreenHeight);
var cmd = `e${x},${y}`;
console.log('cmd:' + cmd)
var ret = usb.send(cmd)
console.log('send ret:', ret)
}

function usbMouseUp(usb) {
var cmd = 'v';
console.log('cmd:' + cmd)
var ret = usb.send(cmd)
console.log('send ret:', ret)
}

发表评论
最新评论
商务合作QQ:3765323427
Copyright © 2021-2024 冰狐智能辅助. All rights reserved. 浙ICP备15043866号 《冰狐智能辅助服务协议》