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)
}