我有一个带有 2 个标签的表单,第一个标签显示 USB 游戏手柄名称(一旦找到),第二个我想显示按下的按钮,这是我目前所拥有的:
Imports Microsoft.DirectX.DirectInput
Public Class Form1
Public _device As Device
Public _state As JoystickState
Public arm As Boolean = True
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Dim gameControllerList As DeviceList
gameControllerList = Manager.GetDevices(DeviceClass.GameControl, EnumDevicesFlags.AttachedOnly)
If (gameControllerList.Count > 0) Then
Dim deviceInstance As DeviceInstance
label.Text = "Found"
For Each deviceInstance In gameControllerList
_device = New Device(deviceInstance.InstanceGuid)
label.Text = deviceInstance.InstanceName
_device.SetDataFormat(DeviceDataFormat.Joystick)
Exit For
Next
Else
label.Text = "not found"
End If
output.Clear()
_device.Acquire()
Call Poll()
End Sub
Public Sub Poll()
Dim buttons() As Byte
Dim i As Integer = 0
_device.Poll()
_state = _device.CurrentJoystickState
buttons = _state.GetButtons()
Dim word As String
word = BitConverter.ToString(buttons)
output.AppendText(word)
End Sub
结束类
我看到的只是输出上的 0,这意味着键盘上按下的按钮未被检测到
有谁知道我该如何解决这个问题?