none
Getting data from two(2) joystick/gamepad in one program only. RRS feed

  • Question

  • This is my ff. codes...

    **********************************************************************************

    Imports System.Runtime.InteropServices

    Public Class Form1

        Declare Function joyGetPosEx Lib "winmm.dll" (ByVal uJoyID As Integer, ByRef pji As JOYINFOEX) As Integer

        <StructLayout(LayoutKind.Sequential)> _
        Public Structure JOYINFOEX
            Public dwSize As Integer
            Public dwFlags As Integer
            Public dwXpos As Integer
            Public dwYpos As Integer
            Public dwZpos As Integer
            Public dwRpos As Integer
            Public dwUpos As Integer
            Public dwVpos As Integer
            Public dwButtons As Integer
            Public dwButtonNumber As Integer
            Public dwPOV As Integer
            Public dwReserved1 As Integer
            Public dwReserved2 As Integer
        End Structure

        Dim myjoyEX As JOYINFOEX

        Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick

            ' Get the joystick information
            Call joyGetPosEx(0, myjoyEX)

            With myjoyEX
                Label10.Text = .dwXpos.ToString          'Up to six axis supported
                Label11.Text = .dwYpos.ToString
                Label12.Text = .dwZpos.ToString
                Label13.Text = .dwRpos.ToString
                Label14.Text = .dwUpos.ToString
                Label15.Text = .dwVpos.ToString
                Label16.Text = .dwButtons.ToString("X")  'Print in Hex, so can see the individual bits associated with the buttons
                Label17.Text = .dwButtonNumber.ToString  'number of buttons pressed at the same time
                Label18.Text = (.dwPOV / 100).ToString     'POV hat (in 1/100ths of degrees, so divided by 100 to give degrees)
            End With
        End Sub

        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            myjoyEX.dwSize = 64
            myjoyEX.dwFlags = &HFF ' All information
            Timer1.Interval = 200  'Update at 5 hz
            Timer1.Start()
        End Sub
    End Class

    **********************************************************************************

    That code is working in one joystick only but if two joystick attached on my computer, the other one doesn't work.

    What will I do?

    Thanks in advanced!

    Sunday, June 24, 2018 7:51 AM

All replies

  • I cannot test, but the first parameter is the identifier of the joystick
    Sunday, June 24, 2018 8:22 AM
  • The API function joyGetPosEx has two parameters, the first parameter represents the ID of the gamepad
    You can try changing the code joyGetPosEx(0, myjoyEX) to joyGetPosEx(this.Id, myjoyEX)


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, June 25, 2018 2:36 AM
  • The API function joyGetPosEx has two parameters, the first parameter represents the ID of the gamepad
    You can try changing the code joyGetPosEx(0, myjoyEX) to joyGetPosEx(this.Id, myjoyEX)


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Hi Alex,

    Welcome to the vb forum. 

    I believe your answer is the same as Castor's?? Did you read Castor's reply?

    Just a peeve I and other forum member have. The CSG's competing for posts with the forum members and or posting the same answer as forum members and or marking other CSG replies as the answer when the other forum members have already answered.

    If you are going to provide the same answer as the previous response then at least improve on the previous response. 

    I would suggest explaining how to obtain the joy stick ID next as that will be the next question the OP has.

    :)

    PS Maybe you just did not notice which I do all the time?  But like I say just a peeve if you can avoid it. :)

    Monday, June 25, 2018 2:17 PM