Hidlibrary只会连续报告零

时间:2017-01-17 19:32:20

标签: c#

设备保持报告00,00,00,00不停止,我试过的设备没有报告正确的字节,它只是零或静音。我能做什么?我试图捕捉鼠标非标准按钮点击,USBlyzer说它发送80 00 00 00,但这里只有零。

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using HidLibrary;

namespace MouseHandler
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        /*private const int VendorId = 0x09DA;
        private const int ProductId = 0x000A;
        private const int VendorId = 0x046D;
        private const int ProductId = 0xC52B;*/
        private const int VendorId = 0x0D8C;
        private const int ProductId = 0x013C;

        private static HidDevice device;
        bool paused = false;

        private void Form1_Load(object sender, EventArgs e)
        {
            device = HidDevices.Enumerate(VendorId, ProductId).FirstOrDefault();
            if (device != null)
            {
                device.OpenDevice();
                device.MonitorDeviceEvents = true;
                device.ReadReport(rreport);
            }
        }
        private void rreport(HidReport report)
        {
            if (!paused)
            {
                write(string.Join(", ", report.Data.Select(b => b.ToString("X2"))));
                device.ReadReport(rreport);
            }
        }
        void write(string text)
        {
            if (ControlInvokeRequired(textBox1, () => write(text))) return;
            textBox1.AppendText(text + Environment.NewLine);
        }
        public bool ControlInvokeRequired(Control c, Action a)
        {
            if (c.InvokeRequired) c.Invoke(new MethodInvoker(delegate { a(); }));
            else return false;

            return true;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            paused = !paused;
            device.ReadReport(rreport);
        }
    }
}

0 个答案:

没有答案