我有一个表单,上面有两个标签,第一个标签显示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,这意味着没有检测到按下键盘上的按钮
有人知道我如何解决这个问题吗?
发布于 2011-07-26 22:40:10
有趣的是,它完全像错误所说的那样:在开始轮询设备之前,您需要获取设备。
_device.Acquire();请注意,这只会在实际的轮询函数之前发生一次。
https://stackoverflow.com/questions/6831670
复制相似问题