const { contextBridge, ipcRenderer } = require('electron') const HID = require('node-hid'); const devices = HID.devices() const logitech = devices.filter(el => el.manufacturer == 'Logitech') const data = new HID.HID(logitech[0].vendorId, logitech[0].productId) // data.on('data', db => { // // 拨片 2 是右拨片,1是左拨片,0是取消 // const bp = db[6] === 2 ? '右拨片' : db[6] === 1 ? "左拨片" : '' // const fx = parseInt(db[44], 10) // 转10进制 // const fxp = fx < 123 ? '左轮' + fx : fx > 132 ? '右轮' + fx : '' // const ym = parseInt(db[46], 10) //油门 // console.log(66, bp, fxp, 255 - ym); // }) contextBridge.exposeInMainWorld('$electron', { send: (channel, args) => ipcRenderer.send(channel, args), once: (channel, listener) => ipcRenderer.once(channel, listener), on: (channel, listener) => ipcRenderer.on(channel, listener), onContrl: (callBack) => data.on('data', db => callBack(db)) })