我一張有2個標籤形式直接輸入,第一個標籤顯示USB遊戲手柄名稱(一旦發現)第二我想顯示的按鈕按下時,這裏是我到目前爲止有:VB 2010的GamePad
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的上輸出,這意味着被推向小鍵盤上的按鍵的arent被檢測
任何人都知道我可以解決這個問題?
得到了它,我需要一個_device.Acquire()在那裏。現在,這樣做有沒有人知道如何檢測按鈕推? –