首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >VB 2010与GamePad的直接输入

VB 2010与GamePad的直接输入
EN

Stack Overflow用户
提问于 2011-07-26 22:31:54
回答 1查看 6.4K关注 0票数 0

我有一个表单,上面有两个标签,第一个标签显示USB游戏板的名称(一旦找到),第二个我想要显示按下的按钮,这是到目前为止我所拥有的:

代码语言:javascript
复制
 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,这意味着没有检测到按下键盘上的按钮

有人知道我如何解决这个问题吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-07-26 22:40:10

有趣的是,它完全像错误所说的那样:在开始轮询设备之前,您需要获取设备。

代码语言:javascript
复制
_device.Acquire();

请注意,这只会在实际的轮询函数之前发生一次。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6831670

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档