首页 > 解决方案 > 捕获使用的 USB 设备名称。VB.net

问题描述

我正在为旋转门创建一个 VB.Net 项目。我的问题是我需要知道使用了特定的 usb rfid 阅读器,以便我可以向旋转栅门发出命令,它将转向什么。例如,如果在 rfid 上点击 id 进入,它将转向进入。

我在互联网上看到过 C# 代码并尝试将其转换为 VB.Net,但不幸的是我迷路了。它使用 RawInputProcessor.dll

我发现的 C#:

protected override void OnSourceInitialized(EventArgs e)
{
    _r = new RawPresentationInput(this, RawInputCaptureMode.Foreground);
    _r.KeyPressed += OnKeyPressed;
    DeviceCount = _r.NumberOfKeyboards;
    base.OnSourceInitialized(e);
}

private void StartWndProcHandler()
{
    _r = new RawPresentationInput(this, RawInputCaptureMode.Foreground);
    _r.KeyPressed += OnKeyPressed;
    DeviceCount = _r.NumberOfKeyboards;
}

public event PropertyChangedEventHandler PropertyChanged;

protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
    PropertyChangedEventHandler propertyChanged = PropertyChanged;
    if (propertyChanged != null)
    {
        propertyChanged(this, new PropertyChangedEventArgs(propertyName));
    }
}

private void OnKeyPressed(object sender, RawInputEventArgs e)
{
    if (this.IsActive)
    {
        Keyboard.ClearFocus();
        Event = e;
        DeviceCount = _r.NumberOfKeyboards;
        if (Event.Device.Name == Configuration.device1_in && e.KeyPressState == KeyPressState.Up)
        {
            //do stuff for the turnstile
        }
    }
}

标签: c#vb.net

解决方案


推荐阅读