Visualizzazione dei risultati da 1 a 2 su 2
  1. #1

    [VB.NET] Configurare e utlizzare joystick con DirectX.DirectInput

    Salve a tutti
    Volevo utilizzare un joystick per dare input al computer per il mio programma, e spulciando il web ho trovato le librerie DirectX, in particolare la classe DirectInput, molto utili, e in effetti lo sono (visto che sono fatte apposta). Ho scritto questo codice:
    codice:
    Public Class Joystick
        Dim Devices As Microsoft.DirectX.DirectInput.DeviceList
        Dim dev As Microsoft.DirectX.DirectInput.DeviceInstance
        Dim gamepadDevice As Microsoft.DirectX.DirectInput.Device
        Dim JoyState As Microsoft.DirectX.DirectInput.JoystickState
        Sub New()
            Devices = Microsoft.DirectX.DirectInput.Manager.GetDevices(Microsoft.DirectX.DirectInput.DeviceClass.GameControl, Microsoft.DirectX.DirectInput.EnumDevicesFlags.AttachedOnly)
            Devices.Reset()
            Devices.MoveNext()
            dev = Devices.Current
            gamepadDevice = New Microsoft.DirectX.DirectInput.Device(dev.InstanceGuid)
        End Sub
    
        Public Function GetPressedButtons() As Byte()
            gamepadDevice.Acquire()
            JoyState = gamepadDevice.CurrentJoystickState
            Return JoyState.GetButtons
        End Function
    
        Public Function GetAxisValue() As Integer()
            Dim Values(1) As Integer
            gamepadDevice.Acquire()
            JoyState = gamepadDevice.CurrentJoystickState
            Values(0) = JoyState.X
            Values(1) = JoyState.Y
            Return Values
        End Function
    
    End Class
    Il problema è che la funzione GetPressedButtons mi restitusice 128 byte tutti uguali a 0 sempre (in teoria dovrebbero essere tanti quanti i bottoni del joystick, cioè 8). Perchè non va?
    Secondo problema: si potrebbe generare un evento quando un tasto del joystick viene premuto?
    Avevo notato nella classe Device il metodo .SetNotificationEvent che richiede come parametro un System.WaitHandle. Può essere utile? Come posso fare?

    Grazie a chiunque provi a rispondermi


  2. #2
    Adesso la funzione GetPressedButtons funziona
    Resta il fatto che voglio far generare un evento!

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.