Kirjautuminen

Haku

Tehtävät

Keskustelu: Ohjelmointikysymykset: VB6: Joygetpos - funktiosta

Sertzio [20.02.2004 11:12:28]

#

Voisko joku kerto joygetpos funktiosta jotain tarpeellista tietoa. Kaikenlainen tieto on tarpeellista. Esim. mitkä sen käyttömahdollisuudet.
Kyseessähän on peliportin lukemiseen tehty funktio...

sooda [20.02.2004 19:07:46]

#

kas tässä sorsaa, ei ole ite tekemääni mutta auttaa ihan varmasti:

Const JOY_BUTTON1 = &H1
Const JOY_BUTTON2 = &H2
Const JOY_BUTTON3 = &H4
Const JOY_BUTTON4 = &H8
Const JOYERR_BASE = 160
Const JOYERR_NOERROR = 0
Const JOYERR_NOCANDO = JOYERR_BASE + 6
Const JOYERR_PARMS = JOYERR_BASE + 5
Const JOYERR_UNPLUGGED = JOYERR_BASE + 7
Const MAXPNAMELEN = 32
Const JOYSTICKID1 = 0
Const JOYSTICKID2 = 1

Private Type JOYINFO
    X As Long
    Y As Long
    Z As Long
    Buttons As Long
End Type

Private Type JOYCAPS
    wMid As Integer
    wPid As Integer
    szPname As String * MAXPNAMELEN
    wXmin As Long
    wXmax As Long
    wYmin As Long
    wYmax As Long
    wZmin As Long
    wZmax As Long
    wNumButtons As Long
    wPeriodMin As Long
    wPeriodMax As Long
End Type

Private Declare Function joyGetDevCaps Lib "winmm.dll" Alias "joyGetDevCapsA" (ByVal id As Long, lpCaps As JOYCAPS, ByVal uSize As _
        Long) As Long
Private Declare Function joyGetNumDevs Lib "winmm.dll" () As Long
Private Declare Function joyGetPos Lib "winmm.dll" (ByVal uJoyID As Long, pji As JOYINFO) As Long

Private Function GetJoyMax(ByVal joy As Integer, JI As JOYINFO) As Boolean

    Dim jc As JOYCAPS
    If joyGetDevCaps(joy, jc, Len(jc)) <> JOYERR_NOERROR Then
        GetJoyMax = False
    Else
        JI.X = jc.wXmax
        JI.Y = jc.wYmax
        JI.Z = jc.wZmax
        JI.Buttons = jc.wNumButtons
        GetJoyMax = True
    End If

End Function

Private Function GetJoyMin(ByVal joy As Integer, JI As JOYINFO) As Boolean

    Dim jc As JOYCAPS
    If joyGetDevCaps(joy, jc, Len(jc)) <> JOYERR_NOERROR Then
        GetJoyMin = False
    Else
        JI.X = jc.wXmin
        JI.Y = jc.wYmin
        JI.Z = jc.wZmin
        JI.Buttons = jc.wNumButtons
        GetJoyMin = True
    End If

End Function

Private Function GetJoystick(ByVal joy As Integer, JI As JOYINFO) As Boolean

    If joyGetPos(joy, JI) <> JOYERR_NOERROR Then
        GetJoystick = False
    Else
        GetJoystick = True
    End If

End Function

Private Function IsJoyPresent(Optional IsConnected As Variant) As Long

    Dim ic As Boolean
    Dim i As Long
    Dim j As Long
    Dim ret As Long
    Dim JI As JOYINFO
    ic = IIf(IsMissing(IsConnected), True, CBool(IsConnected))
    i = joyGetNumDevs
    If ic Then
        j = 0
        Do While i > 0
            i = i - 1
            If joyGetPos(i, JI) = JOYERR_NOERROR Then
                j = j + 1
            End If
        Loop
        IsJoyPresent = j
    Else
        IsJoyPresent = i
    End If

End Function

Private Sub Timer1_Timer()

    Dim JInfo As JOYINFO
    Cls
    Print "Joysticks ID    :" + Str$(IsJoyPresent(False))
    Print "Joysticks found :" + Str$(IsJoyPresent(True))
    GetJoyMax JOYSTICKID1, JInfo
    Print "Max X :" + Str$(JInfo.X)
    Print "Max Y :" + Str$(JInfo.Y)
    Print "Max Z:" + Str$(JInfo.Z)
    GetJoyMin JOYSTICKID1, JInfo
    Print "Min X :" + Str$(JInfo.X)
    Print "Min Y :" + Str$(JInfo.Y)
    Print "Min Z:" + Str$(JInfo.Z)
    Print "Buttons   :" + Str$(JInfo.Buttons)
    GetJoystick JOYSTICKID1, JInfo
    Print "Button    :" + Str$(JInfo.Buttons)
    Print "Current X :" + Str$(JInfo.X)
    Print "Current Y :" + Str$(JInfo.Y)

End Sub

tarttee timerin.

Vastaus

Aihe on jo aika vanha, joten et voi enää vastata siihen.

Tietoa sivustosta