Newsgroup: it.comp.lang.visual-basic
Titolo: VB 2005 Joystick

Domandina corta:
E' possibile intercettare i tasti che vengono premuti sul joystick per
mostrarli nella mia applicazione?
Ciao,
Daniele

mostrarli nella mia applicazione?
qui ne hanno parlato un po', pare che occorrano le DirectX (brrrr....)
e rimandano al sito della ms
http://www.thescripts.com/forum/thread384902.html
però la pagina non c'è
a questo punto io prenderei in considerazione l'uso delle vecchie API VB6
o 
tradurre in VBNet questa classe VB6   JoyStick.cls   trovata in rete
(che non mi ricordo se ho mai provato o no, per cui potrebbe essere anche
buggy, occhio) che non dovrebbe essere difficile:
VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
END
Attribute VB_Name = "JoyStick"
Attribute VB_Creatable = True
Attribute VB_Exposed = False
Private Type JOYINFOEX
   dwSize As Long                      ' size of structure
   dwFlags As Long                     ' flags to indicate what to return
   dwXpos As Long                      ' x position
   dwYpos As Long                      ' y position
   dwZpos As Long                      ' z position
   dwRpos As Long                      ' rudder/4th axis position
   dwUpos As Long                      ' 5th axis position
   dwVpos As Long                      ' 6th axis position
   dwButtons As Long                   ' button states
   dwButtonNumber As Long              ' current button number pressed
   dwPOV As Long                       ' point of view state
   dwReserved1 As Long                 ' reserved for communication between
winmm driver
   dwReserved2 As Long                 ' reserved for future expansion
End Type
Private Declare Function joyGetPosEx Lib "winmm.dll" (ByVal uJoyID As Long,
pji As JOYINFOEX) As Long
Private Const JOYSTICKID1 = 0
Private Const JOYSTICKID2 = 1
Private Const JOY_RETURNBUTTONS = &H80&
Private Const JOY_RETURNCENTERED = &H400&
Private Const JOY_RETURNPOV = &H40&
Private Const JOY_RETURNR = &H8&
Private Const JOY_RETURNU = &H10
Private Const JOY_RETURNV = &H20
Private Const JOY_RETURNX = &H1&
Private Const JOY_RETURNY = &H2&
Private Const JOY_RETURNZ = &H4&
Private Const JOY_RETURNALL = (JOY_RETURNX Or JOY_RETURNY Or JOY_RETURNZ Or
JOY_RETURNR Or JOY_RETURNU Or JOY_RETURNV Or JOY_RETURNPOV Or
JOY_RETURNBUTTONS)
Private ji As JOYINFOEX     ' joystick state buffer
Function JoystickX(joyid As Integer) As Long
'returns the x axis
'put  the joystick number in joyid IE. 1 2
ji.dwSize = Len(ji)
ji.dwFlags = JOY_RETURNALL
If joyid = 2 Then
rc = joyGetPosEx(JOYSTICKID2, ji)
Else
rc = joyGetPosEx(JOYSTICKID1, ji)
End If
JoystickX = ji.dwXpos
End Function
Function JoystickY(joyid As Integer) As Long
'returns the y axis of the joystick
ji.dwSize = Len(ji)
ji.dwFlags = JOY_RETURNALL
If joyid = 2 Then
rc = joyGetPosEx(JOYSTICKID2, ji)
Else
rc = joyGetPosEx(JOYSTICKID1, ji)
End If
JoystickY = ji.dwYpos
End Function
Function Button(joyid As Integer, buttonnum As String) As Boolean
'enter joystick id in joy id IE. 1 2
'enter buttonid in buttonnum IE. A B C D
ji.dwSize = Len(ji)
ji.dwFlags = JOY_RETURNALL
If joyid = 2 Then
rc = joyGetPosEx(JOYSTICKID2, ji)
Else
rc = joyGetPosEx(JOYSTICKID1, ji)
End If
ab = ji.dwButtons
If ab - 8 >= 0 Then
bD = True
ab = ab - 8
Else
bD = False
End If
If ab - 4 >= 0 Then
bC = True
ab = ab - 4
Else
bC = False
End If
If ab - 2 >= 0 Then
bB = True
ab = ab - 2
Else
bB = False
End If
If ab - 1 >= 0 Then
bA = True
ab = ab - 1
Else
bA = False
End If
Select Case LCase(buttonnum)
Case "a"
Button = bA
Case Is = "b"
Button = bB
Case Is = "c"
Button = bC
Case Is = "d"
Button = bD
Case Else
End Select
End Function
Function POV(joyid As Integer) As Long
'returns the pov axis
'put  the joystick number in joyid IE. 1 2
ji.dwSize = Len(ji)
ji.dwFlags = JOY_RETURNALL
If joyid = 2 Then
rc = joyGetPosEx(JOYSTICKID2, ji)
Else
rc = joyGetPosEx(JOYSTICKID1, ji)
End If
POV = ji.dwPOV
End Function
Function Throttle(joyid As Integer) As Long
'returns the Z Or throttle axis
'put  the joystick number in joyid IE. 1 2
ji.dwSize = Len(ji)
ji.dwFlags = JOY_RETURNALL
If joyid = 2 Then
rc = joyGetPosEx(JOYSTICKID2, ji)
Else
rc = joyGetPosEx(JOYSTICKID1, ji)
End If
Throttle = ji.dwZpos
End Function

 End Function
Grazie mille, mi metto subito al lavoro!

Grazie mille, mi metto subito al lavoro!
se va, magari riposta qui la versione tradotta in Net

Ecco la versione .NET
    Private Structure JOYINFOEX
        Dim dwSize As Integer                      ' size of structure
        Dim dwFlags As Integer                     ' flags to indicate
what to return
        Dim dwXpos As Integer                      ' x position
        Dim dwYpos As Integer                      ' y position
        Dim dwZpos As Integer                      ' z position
        Dim dwRpos As Integer                      ' rudder/4th axis
position
        Dim dwUpos As Integer                      ' 5th axis position
        Dim dwVpos As Integer                      ' 6th axis position
        Dim dwButtons As Integer                   ' button states
        Dim dwButtonNumber As Integer              ' current button
number pressed
        Dim dwPOV As Integer                       ' point of view
state
        Dim dwReserved1 As Integer                 ' reserved for
communication between winmm driver
        Dim dwReserved2 As Integer                 ' reserved for
future expansion
    End Structure
    Private Declare Function joyGetPosEx Lib "winmm.dll" (ByVal uJoyID
As Long, ByVal pji As JOYINFOEX) As Long
    Private Const JOYSTICKID1 As Short = 0
    Private Const JOYSTICKID2 As Short = 1
    Private Const JOY_RETURNBUTTONS As Integer = &H80
    Private Const JOY_RETURNCENTERED As Integer = &H400
    Private Const JOY_RETURNPOV As Integer = &H40
    Private Const JOY_RETURNR As Integer = &H8
    Private Const JOY_RETURNU As Short = &H10S
    Private Const JOY_RETURNV As Short = &H20S
    Private Const JOY_RETURNX As Integer = &H1
    Private Const JOY_RETURNY As Integer = &H2
    Private Const JOY_RETURNZ As Integer = &H4
    Private Const JOY_RETURNALL = (JOY_RETURNX Or JOY_RETURNY Or
JOY_RETURNZ Or JOY_RETURNR Or JOY_RETURNU Or JOY_RETURNV Or
JOY_RETURNPOV Or JOY_RETURNBUTTONS)
    Private ji As JOYINFOEX ' joystick state buffer
    Dim rc
    Function JoystickX(ByVal joyid As Integer) As Long
        'returns the x axis
        'put  the joystick number in joyid IE. 1 2
        ji.dwSize = Len(ji)
        ji.dwFlags = JOY_RETURNALL
        If joyid = 2 Then
            rc = joyGetPosEx(JOYSTICKID2, ji)
        Else
            rc = joyGetPosEx(JOYSTICKID1, ji)
        End If
        JoystickX = ji.dwXpos
    End Function
    Function JoystickY(ByVal joyid As Integer) As Long
        'returns the y axis of the joystick
        ji.dwSize = Len(ji)
        ji.dwFlags = JOY_RETURNALL
        If joyid = 2 Then
            rc = joyGetPosEx(JOYSTICKID2, ji)
        Else
            rc = joyGetPosEx(JOYSTICKID1, ji)
        End If
        JoystickY = ji.dwYpos
    End Function
    Dim bD
    Dim bC
    Dim bB
    Dim bA
    Function Button(ByVal joyid As Integer, ByVal buttonnum As String)
As Boolean
        'enter joystick id in joy id IE. 1 2
        'enter buttonid in buttonnum IE. A B C D
        ji.dwSize = Len(ji)
        ji.dwFlags = JOY_RETURNALL
        If joyid = 2 Then
            rc = joyGetPosEx(JOYSTICKID2, ji)
        Else
            rc = joyGetPosEx(JOYSTICKID1, ji)
        End If
        Dim ab

    Function POV(ByVal joyid As Integer) As Long
        'returns the pov axis
        'put  the joystick number in joyid IE. 1 2
        ji.dwSize = Len(ji)
        ji.dwFlags = JOY_RETURNALL
        If joyid = 2 Then
            rc = joyGetPosEx(JOYSTICKID2, ji)
        Else
            rc = joyGetPosEx(JOYSTICKID1, ji)
        End If
        POV = ji.dwPOV
    End Function
    Function Throttle(ByVal joyid As Integer) As Long
        'returns the Z Or throttle axis
        'put  the joystick number in joyid IE. 1 2
        ji.dwSize = Len(ji)
        ji.dwFlags = JOY_RETURNALL
        If joyid = 2 Then
            rc = joyGetPosEx(JOYSTICKID2, ji)
        Else


Non capisco, però, se sto sbagliando ad usarlo oppure ho tradotto
male:
se faccio, con un timer:
Label1.Text = JoystickY(1)
allora Label1.Text diventa "0".
E anche premendo tutti i pulsanti non si muove.
Perchè?
Ciao!