🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: free.it.visual-basic
Article #3138

Re: api 16 bit x controllo joystick

#3138
From: Gianni
Date: Mon, 21 Oct 2002 20:12
157 lines
5806 bytes
"Enrico" <enricogoldin@tiscalinet.it> ha scritto nel messaggio
news:ap1lp7$8ka$1@lacerta.tiscalinet.it...
> eccoti un esempio
> ' defines and structures
> 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 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
> '  If IsConnected is False then it returns the number of
> '  joysticks the driver supports. (But may not be connected)
> '
> '  If IsConnected is True the it returns the number of
> '  joysticks present and connected.
> '
> '  IsConnected is true by default.
> 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   'Joysticks id's are 0 and 1
>          If joyGetPos(i, JI) = JOYERR_NOERROR Then
>             j = j + 1
>          End If
>       Loop
>
>       IsJoyPresent = j
>    Else
>       IsJoyPresent = i
>    End If
>
> End Function
> '  Fills the ji structure with the minimum x, y, and z
> '  coordinates.  Buttons is filled with the number of
> '  buttons.
> 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
> '  Fills the ji structure with the maximum x, y, and z
> '  coordinates.  Buttons is filled with the number of
> '  buttons.
> 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 Sub Form_Paint()
>     'KPD-Team 1999
>     'URL: http://www.allapi.net/
>     'E-Mail: KPDTeam@Allapi.net
>     Dim JInfo As JOYINFO
>     'Clear the form
>     Me.Cls
>     'Print the information to the form
>     Me.Print "Number of joysticks the driver supports:" +
> Str$(IsJoyPresent(False))
>     Me.Print "Number of connected joysticks:" + Str$(IsJoyPresent(True))
>     GetJoystick JOYSTICKID1, JInfo
>     Me.Print "Number of buttons:" + Str$(JInfo.Buttons)
>     GetJoyMax JOYSTICKID1, JInfo
>     Me.Print "Max X:" + Str$(JInfo.X)
>     Me.Print "Max Y:" + Str$(JInfo.Y)
>     Me.Print "Max Z:" + Str$(JInfo.Z)
>     GetJoyMin JOYSTICKID1, JInfo
>     Me.Print "Min X:" + Str$(JInfo.X)
>     Me.Print "Min Y:" + Str$(JInfo.Y)
>     Me.Print "Min Z:" + Str$(JInfo.Z)
> End Sub
>
> enrico

Ciao Enrico, ti ringrazio per la risposta. Purtroppo il tuo esempio utilizza
la funzione api: "joyGetPos Lib "winmm.dll" a 32 bit eche quindi non funzia
in un programma scritto con vb3.

Io devo integrare la lettura dei pulsanti del joystick all'interno di un
programma scritto con vb3.

Per cui l'unica soluzione mi sembra sia quella di usare l'api a 16 bit:
Declare Function joygetpos Lib "Mmsystem" (ByVal wjoyld As Integer, lpinfo
As joyinfo) As Integer

Un saluto gianni.
Technical Details
Message-ID: <ap1n42$9jl$1@lacerta.tiscalinet.it>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-03!sn-xit-01!sn-xit-04!supernews.com!news.maxwell.syr.edu!news.mailgate.org!draco.tiscalinet.it!not-for-mail
References: <ap0nma$iuh$1@news.flashnet.it> <ap1lp7$8ka$1@lacerta.tiscalinet.it>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f94ee,a2087cfd8f50a8df
X-Google-Attributes: gidf94ee,public
X-Google-ArrivalTime: 2002-10-21 13:18:01 PST
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-03!sn-xit-01!sn-xit-04!supernews.com!news.maxwell.syr.edu!news.mailgate.org!draco.tiscalinet.it!not-for-mail
From: "Gianni" <g.fadda@tiscalinet.it>
Newsgroups: free.it.visual-basic
Subject: Re: api 16 bit x controllo joystick
Date: Mon, 21 Oct 2002 22:12:41 +0200
Organization: Dedalus
Lines: 160
Message-ID: <ap1n42$9jl$1@lacerta.tiscalinet.it>
References: <ap0nma$iuh$1@news.flashnet.it> <ap1lp7$8ka$1@lacerta.tiscalinet.it>
Reply-To: "Gianni" <g.fadda@tiscalinet.it>
NNTP-Posting-Host: ppp-62-11-87-240.dialup.tiscali.it
X-Trace: lacerta.tiscalinet.it 1035231170 9845 62.11.87.240 (21 Oct 2002 20:12:50 GMT)
X-Complaints-To: newsadmin@it.tiscali.com
NNTP-Posting-Date: 21 Oct 2002 20:12:50 GMT
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 5.50.4522.1200
X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4522.1200