2011-07-26 16 views
0

2つのラベルが付いたフォームがあり、最初のラベルにはUSBゲームパッドの名前が表示されます(2番目のボタンはプッシュボタンを表示したい、ここまでは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のですか?

+0

私はそこに_device.Acquire()が必要でした。これで、誰かがプッシュボタンを検出する方法を知っていますか? –

答えて

2

面白いことに、面白いことに、それはまさにこのエラーと同じです。ポーリングを開始する前にデバイスを取得する必要があります。

_device.Acquire(); 

これは、実際のポーリング機能の前に一度だけ発生することに注意してください。

+0

ええ、私はちょうど同じと思った、あなたはどのキーが押されたかを検出する方法を知っていますか? –

+0

もちろん、 '_state'(途方もない名前付けスキーム)を取得したら、' Byte() 'を返す' GetButtons'を呼び出します。その後、ボタンの配列を反復処理し、 '0'でなければ、それを押します。私はバイト配列に()バイト ボタン=の_state.GetButtons() として 点心ボタンを()_state.GetButtonsを設定する必要があります参照 – Blindy

+0

だろうと仕事のようなもの? –

関連する問題