1

我的蒸汽控制器今天到货了,我正要实现检查蒸汽控制器上的按钮是否被按下的代码。我正在使用 Steamworks.NET 包装器。但不知何故 GetControllerState 总是返回 0 我不知道为什么。有任何想法吗?

这是我的代码:

    Dim SteamAPI_Initialized As Boolean
Dim Controller_Initialized As Boolean

Private Sub OnEnable()
    SteamAPI_Initialized = Steamworks.SteamAPI.Init()
    If SteamAPI_Initialized Then
        Controller_Initialized = Steamworks.SteamController.Init("C:\Users\User\AppData\Local\Temporary Projects\WindowsApplication1\bin\Debug\controller.vdf")
    End If
    If Not SteamAPI_Initialized Then
        MsgBox("Failed to initialize SteamAPI!")
    ElseIf Not Controller_Initialized Then
        MsgBox("Failed to initialize SteamController!")
    End If
End Sub

Private Sub OnDisable()
    If Controller_Initialized Then
        Steamworks.SteamController.Shutdown()
    End If
    If SteamAPI_Initialized Then
        Steamworks.SteamAPI.Shutdown()
    End If
End Sub
Private state As New Steamworks.SteamControllerState_t
Private Sub CH_Button1_Click(sender As Object, e As EventArgs) Handles CH_Button1.Click
    OnEnable()
    Timer1.Enabled = True
End Sub

Private Sub Form1_FormClosing(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing
    OnDisable()
End Sub
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
    If Controller_Initialized Then
        Steamworks.SteamAPI.RunCallbacks()
        Steamworks.SteamController.RunFrame()
        If Steamworks.SteamController.GetControllerState(0, state) Then 'always returns 0
            If (state.ulButtons And Steamworks.Constants.STEAM_BUTTON_LEFTPAD_CLICKED_MASK) <> 0 Then
                MsgBox("RIGHT_TRIGGER")
            End If
        End If
    End If
End Sub
4

0 回答 0