Results 1 to 2 of 2

Thread: Joy Stick Info

  1. #1

    Thread Starter
    Frenzied Member SeanK's Avatar
    Join Date
    May 2002
    Location
    Boston MA
    Posts
    1,160

    Joy Stick Info

    I've looked around but can't seem to find anything on how to retrieve joy stick info.

    Any one know?
    Beantown Boy
    Please use [highlight=vb]your code goes in here[/highlight] tags when posting code.
    When you have received an answer to your question, please mark it as resolved using the Thread Tools menu.

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    From AllApi.Com

    VB Code:
    1. ' defines and structures
    2. Const JOY_BUTTON1 = &H1
    3. Const JOY_BUTTON2 = &H2
    4. Const JOY_BUTTON3 = &H4
    5. Const JOY_BUTTON4 = &H8
    6. Const JOYERR_BASE = 160
    7. Const JOYERR_NOERROR = (0)
    8. Const JOYERR_NOCANDO = (JOYERR_BASE + 6)
    9. Const JOYERR_PARMS = (JOYERR_BASE + 5)
    10. Const JOYERR_UNPLUGGED = (JOYERR_BASE + 7)
    11. Const MAXPNAMELEN = 32
    12. Const JOYSTICKID1 = 0
    13. Const JOYSTICKID2 = 1
    14.  
    15. Private Type JOYINFO
    16.    X As Long
    17.    Y As Long
    18.    Z As Long
    19.    Buttons As Long
    20. End Type
    21. Private Type JOYCAPS
    22.    wMid As Integer
    23.    wPid As Integer
    24.    szPname As String * MAXPNAMELEN
    25.    wXmin As Long
    26.    wXmax As Long
    27.    wYmin As Long
    28.    wYmax As Long
    29.    wZmin As Long
    30.    wZmax As Long
    31.    wNumButtons As Long
    32.    wPeriodMin As Long
    33.    wPeriodMax As Long
    34.  End Type
    35.  
    36. Private Declare Function joyGetDevCaps Lib "winmm.dll" Alias "joyGetDevCapsA" (ByVal id As Long, lpCaps As JOYCAPS, ByVal uSize As Long) As Long
    37. Private Declare Function joyGetNumDevs Lib "winmm.dll" () As Long
    38. Private Declare Function joyGetPos Lib "winmm.dll" (ByVal uJoyID As Long, pji As JOYINFO) As Long
    39. Private Function GetJoystick(ByVal joy As Integer, JI As JOYINFO) As Boolean
    40.    If joyGetPos(joy, JI) <> JOYERR_NOERROR Then
    41.       GetJoystick = False
    42.    Else
    43.       GetJoystick = True
    44.    End If
    45. End Function
    46. '  If IsConnected is False then it returns the number of
    47. '  joysticks the driver supports. (But may not be connected)
    48. '
    49. '  If IsConnected is True the it returns the number of
    50. '  joysticks present and connected.
    51. '
    52. '  IsConnected is true by default.
    53. Private Function IsJoyPresent(Optional IsConnected As Variant) As Long
    54.    Dim ic As Boolean
    55.    Dim i As Long
    56.    Dim j As Long
    57.    Dim ret As Long
    58.    Dim JI As JOYINFO
    59.  
    60.    ic = IIf(IsMissing(IsConnected), True, CBool(IsConnected))
    61.  
    62.    i = joyGetNumDevs
    63.  
    64.    If ic Then
    65.       j = 0
    66.       Do While i > 0
    67.          i = i - 1   'Joysticks id's are 0 and 1
    68.          If joyGetPos(i, JI) = JOYERR_NOERROR Then
    69.             j = j + 1
    70.          End If
    71.       Loop
    72.  
    73.       IsJoyPresent = j
    74.    Else
    75.       IsJoyPresent = i
    76.    End If
    77.  
    78. End Function
    79. '  Fills the ji structure with the minimum x, y, and z
    80. '  coordinates.  Buttons is filled with the number of
    81. '  buttons.
    82. Private Function GetJoyMin(ByVal joy As Integer, JI As JOYINFO) As Boolean
    83.    Dim jc As JOYCAPS
    84.  
    85.    If joyGetDevCaps(joy, jc, Len(jc)) <> JOYERR_NOERROR Then
    86.       GetJoyMin = False
    87.  
    88.    Else
    89.       JI.X = jc.wXmin
    90.       JI.Y = jc.wYmin
    91.       JI.Z = jc.wZmin
    92.       JI.Buttons = jc.wNumButtons
    93.  
    94.       GetJoyMin = True
    95.    End If
    96. End Function
    97. '  Fills the ji structure with the maximum x, y, and z
    98. '  coordinates.  Buttons is filled with the number of
    99. '  buttons.
    100. Private Function GetJoyMax(ByVal joy As Integer, JI As JOYINFO) As Boolean
    101.    Dim jc As JOYCAPS
    102.    If joyGetDevCaps(joy, jc, Len(jc)) <> JOYERR_NOERROR Then
    103.       GetJoyMax = False
    104.    Else
    105.       JI.X = jc.wXmax
    106.       JI.Y = jc.wYmax
    107.       JI.Z = jc.wZmax
    108.       JI.Buttons = jc.wNumButtons
    109.       GetJoyMax = True
    110.    End If
    111. End Function
    112. Private Sub Form_Paint()
    113.     'KPD-Team 1999
    114.     'URL: [url]http://www.allapi.net/[/url]
    115.     'E-Mail: [email][email protected][/email]
    116.     Dim JInfo As JOYINFO
    117.     'Clear the form
    118.     Me.Cls
    119.     'Print the information to the form
    120.     Me.Print "Number of joysticks the driver supports:" + Str$(IsJoyPresent(False))
    121.     Me.Print "Number of connected joysticks:" + Str$(IsJoyPresent(True))
    122.     GetJoystick JOYSTICKID1, JInfo
    123.     Me.Print "Number of buttons:" + Str$(JInfo.Buttons)
    124.     GetJoyMax JOYSTICKID1, JInfo
    125.     Me.Print "Max X:" + Str$(JInfo.X)
    126.     Me.Print "Max Y:" + Str$(JInfo.Y)
    127.     Me.Print "Max Z:" + Str$(JInfo.Z)
    128.     GetJoyMin JOYSTICKID1, JInfo
    129.     Me.Print "Min X:" + Str$(JInfo.X)
    130.     Me.Print "Min Y:" + Str$(JInfo.Y)
    131.     Me.Print "Min Z:" + Str$(JInfo.Z)
    132. End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width