An example on how to use the Win32 Joystick functions

Windows specific forum
User avatar
Flype
Addict
Addict
Posts: 1542
Joined: Tue Jul 22, 2003 5:02 pm
Location: In a long distant galaxy

An example on how to use the Win32 Joystick functions

Post by Flype »

Code: Select all

; 
; Win32 / Multimedia / Joystick
; 

Enumeration ; #JOYCAPS_
  #JOYCAPS_HASZ = 1
  #JOYCAPS_HASR = 2
  #JOYCAPS_HASU = 4
  #JOYCAPS_HASV = 8
  #JOYCAPS_HASPOV = 16
  #JOYCAPS_POV4DIR = 32
  #JOYCAPS_POVCTS = 64
EndEnumeration

Procedure.l MyDraw(*caps.JOYCAPS, *info.JOYINFOEX)
  
  TextColor = $F0F0F0
  LineColor = $966E47
  FrontColor = $A77F58
  
  iw = ImageWidth(0)
  ih = ImageHeight(0)
  
  iw2 = iw - 50
  ih2 = ih - 50
  
  If StartDrawing(ImageOutput(0))
    
    x = (*info\dwXpos*iw2)/*caps\wXmax
    y = (*info\dwYpos*ih2)/*caps\wYmax
    w = (*info\dwRpos*iw2)/*caps\wRmax
    h = (*info\dwZpos*ih2)/*caps\wZmax
    
    DrawingMode(1)
    DrawingFont(FontID(0))
    
    Box(0,0,iw,ih,FrontColor)
    Line(iw/2-2,0,0,ih,LineColor)
    Line(0,ih/2-2,iw,0,LineColor)
    Box(25,25,iw2,ih2,LineColor)
    Line(iw/2-2,25,0,ih2,FrontColor)
    Line(25,ih/2-2,iw2,0,FrontColor)
    Line(x+25,0,0,ih,FrontColor)
    Line(0,y+25,iw,0,FrontColor)
    Ellipse(25+x,25+y,w/2,h/2,LineColor)
    Ellipse(25+x,25+y,(w/2)-5,(h/2)-5,FrontColor)
    Line(x+25,y-h/2+25,0,h,LineColor)
    Line(x-w/2+25,y+25,w,0,LineColor)
    
    y = 15
    For i = 0 To *caps\wMaxButtons - 1
      If (i % 4) = 0
        x = iw-145 : y + 26
      EndIf
      x + 26
      button = Pow(2,i)
      If (*info\dwButtons & button)
        Circle(x,y,12,FrontColor)
        Circle(x,y,10,$193CC0)
      Else
        DrawingMode(4)
        Circle(x,y,12,FrontColor)
        Circle(x,y,11,LineColor)
        DrawingMode(1)
      EndIf
      If (i<*caps\wNumButtons)
        DrawText(x-7,y-6,RSet(Str(i+1),2,"0"),TextColor)
      Else
        DrawText(x-7,y-6,RSet(Str(i+1),2,"0"),FrontColor)
      EndIf
    Next
    
    x = 10
    
    DrawText(x,10,"Name: "+PeekS(@*caps\szPname),TextColor)
    DrawText(x,25,"Manufacturer: 0x"+Hex(*caps\wMid),TextColor)
    DrawText(x,40,"Product: 0x"+Hex(*caps\wPid),TextColor)
    DrawText(x,55,"RegKey: "+PeekS(@*caps\szRegKey),TextColor)
    DrawText(x,70,"OEM: "+PeekS(@*caps\szOEMVxD),TextColor)
    
    DrawText(x,105,"Nb Axes: "+Str(*caps\wNumAxes)+"/"+Str(*caps\wMaxAxes),TextColor)
    DrawText(x,120,"Period: "+Str(*caps\wPeriodMin)+"/"+Str(*caps\wPeriodMax)+" ms",TextColor)
    DrawText(x,150,"HasZ: "+Str((*caps\wCaps & #JOYCAPS_HASZ)/#JOYCAPS_HASZ),TextColor)
    DrawText(x,165,"HasR: "+Str((*caps\wCaps & #JOYCAPS_HASR)/#JOYCAPS_HASR),TextColor)
    DrawText(x,180,"HasU: "+Str((*caps\wCaps & #JOYCAPS_HASU)/#JOYCAPS_HASU),TextColor)
    DrawText(x,195,"HasV: "+Str((*caps\wCaps & #JOYCAPS_HASV)/#JOYCAPS_HASV),TextColor)
    DrawText(x,210,"HasPOV: "+Str((*caps\wCaps & #JOYCAPS_HASPOV)/#JOYCAPS_HASPOV),TextColor)
    DrawText(x,225,"POV4DIR: "+Str((*caps\wCaps & #JOYCAPS_POV4DIR)/#JOYCAPS_POV4DIR),TextColor)
    DrawText(x,240,"POVCTS: "+Str((*caps\wCaps & #JOYCAPS_POVCTS)/#JOYCAPS_POVCTS),TextColor)
    DrawText(x,255,"Caps: %"+RSet(Bin(*caps\wCaps),7,"0"),TextColor)
    
    DrawText(x,285,"POV: "+Str(*info\dwPOV),TextColor)
    DrawText(x,315,"X: "+RSet(Str(*info\dwXpos),5,"0")+" ("+Str(*caps\wXmin)+","+Str(*caps\wXmax)+")",TextColor)
    DrawText(x,330,"Y: "+RSet(Str(*info\dwYpos),5,"0")+" ("+Str(*caps\wYmin)+","+Str(*caps\wYmax)+")",TextColor)
    DrawText(x,345,"Z: "+RSet(Str(*info\dwZpos),5,"0")+" ("+Str(*caps\wZmin)+","+Str(*caps\wZmax)+")",TextColor)
    DrawText(x,360,"R: "+RSet(Str(*info\dwRpos),5,"0")+" ("+Str(*caps\wRmin)+","+Str(*caps\wRmax)+")",TextColor)
    DrawText(x,375,"U: "+RSet(Str(*info\dwUpos),5,"0")+" ("+Str(*caps\wUmin)+","+Str(*caps\wUmax)+")",TextColor)
    DrawText(x,390,"V: "+RSet(Str(*info\dwVpos),5,"0")+" ("+Str(*caps\wVmin)+","+Str(*caps\wVmax)+")",TextColor)
    
    DrawText(iw-175,ih-15,"Buttons: %"+RSet(Bin(*info\dwButtons),16,"0"),TextColor)
    
    StopDrawing()
    
    SetGadgetState(0,ImageID(0))
    
  EndIf
  
EndProcedure

iw = 640
ih = 480

If OpenWindow(0,0,0,iw,ih,#PB_Window_SystemMenu|#PB_Window_ScreenCentered,"Joystick (Win32)")
  
  If CreateGadgetList(WindowID(0))
    CreateImage(0,iw,ih)
    ImageGadget(0,0,0,iw,ih,ImageID(0))
    LoadFont(0,"Verdana",7,#PB_Font_HighQuality)
  EndIf
  
  If joySetCapture_(WindowID(0),#JOYSTICKID1,#Null,#False) = #JOYERR_NOERROR
    If joyGetDevCaps_(#JOYSTICKID1,joyCaps.JOYCAPS,SizeOf(JOYCAPS)) = #JOYERR_NOERROR
      ; done
    EndIf
  EndIf
  
  joyInfoEx.JOYINFOEX
  joyInfoEx\dwFlags = #JOY_RETURNALL
  joyInfoEx\dwSize = SizeOf(JOYINFOEX)
  
  Repeat
    
    Select WaitWindowEvent(50)
      Case #PB_Event_CloseWindow: Break
    EndSelect
    
    If joyGetPosEx_(#JOYSTICKID1,joyInfoEx) = #JOYERR_NOERROR
      MyDraw(joyCaps,joyInfoEx)
    EndIf
    
    Delay(1)
    
  ForEver
  
  If joyReleaseCapture_(#JOYSTICKID1) = #JOYERR_NOERROR
    ; done
  EndIf

EndIf
No programming language is perfect. There is not even a single best language.
There are only languages well suited or perhaps poorly suited for particular purposes. Herbert Mayer
coma
Enthusiast
Enthusiast
Posts: 164
Joined: Fri Aug 15, 2003 3:46 am
Location: Canada

Post by coma »

excellent.
it works perfectly with my ps2 pad and my usb adapter :)
(and the interface is beautiful)

what is the difference with DirectInput programming (i mean directly use dinput.dll) ? no disadvantages ?
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Re: An example on how to use the Win32 Joystick functions

Post by PB »

Flype wrote: Enumeration ; #JOYCAPS_
#JOYCAPS_HASZ = 1
#JOYCAPS_HASR = 2
#JOYCAPS_HASU = 4
#JOYCAPS_HASV = 8
#JOYCAPS_HASPOV = 16
#JOYCAPS_POV4DIR = 32
#JOYCAPS_POVCTS = 64
EndEnumeration
In case you don't know: Enumeration is used when you DON'T want to declare any
constants with a value, so having Enumeration/EndEnumeration above, while it
does work, is pointless -- like declaring a Global variable that isn't used globally.
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
User avatar
Flype
Addict
Addict
Posts: 1542
Joined: Tue Jul 22, 2003 5:02 pm
Location: In a long distant galaxy

Post by Flype »

coma wrote:excellent.
it works perfectly with my ps2 pad and my usb adapter :)
(and the interface is beautiful)

what is the difference with DirectInput programming (i mean directly use dinput.dll) ? no disadvantages ?
I don't know exactly, i assumed it's easier to use the winmm.lib than the dinput.dll, but it's as you wish.
I noticed that the driver of my controller device (Saitek) use DirectX and the DINPUT.dll, so...
PB wrote:In case you don't know: Enumeration is used when you DON'T want to declare any
constants with a value, so having Enumeration/EndEnumeration above, while it
does work, is pointless -- like declaring a Global variable that isn't used globally.
Yes PB i know that. I often do this way just to be able to 'fold' the constant declaration. :wink:
But i assume i should use the brackets ';{' and '};'
No programming language is perfect. There is not even a single best language.
There are only languages well suited or perhaps poorly suited for particular purposes. Herbert Mayer
coma
Enthusiast
Enthusiast
Posts: 164
Joined: Fri Aug 15, 2003 3:46 am
Location: Canada

Post by coma »

well, after some research, the main limitations are : only two joysticks, and no force feedback.
but it's perfect for what I need.
User avatar
Flype
Addict
Addict
Posts: 1542
Joined: Tue Jul 22, 2003 5:02 pm
Location: In a long distant galaxy

Post by Flype »

>only two joysticks

not only two joystick !
you can use up to 16 joysticks (i only have 2 joysticks so i have not tested but it's somewhere on the doc).
#JOYSTICKID1 and #JOYSTICKID2 are defined in the winmm.h but you can specify 3, 4, 5, and so on...

Code: Select all

joyGetPosEx

The joyGetPosEx function queries a joystick for its position and button status.

MMRESULT joyGetPosEx(
  UINT uJoyID,     
  LPJOYINFOEX pji  
);

Parameters

uJoyID

Identifier of the joystick to be queried. Valid values for uJoyID range from zero (JOYSTICKID1) to 15, except for Windows NT 4.0. For Windows NT 4.0, valid values are limited to JOYSTICKID1 and JOYSTICKID2.
http://msdn.microsoft.com/library/defau ... tposex.asp

>force feedback

You are surely true because i don't see anything about that in the winmm.
No programming language is perfect. There is not even a single best language.
There are only languages well suited or perhaps poorly suited for particular purposes. Herbert Mayer
coma
Enthusiast
Enthusiast
Posts: 164
Joined: Fri Aug 15, 2003 3:46 am
Location: Canada

Post by coma »

Flype wrote:>only two joysticks

not only two joystick !
you can use up to 16 joysticks (i only have 2 joysticks so i have not tested but it's somewhere on the doc).
#JOYSTICKID1 and #JOYSTICKID2 are defined in the winmm.h but you can specify 3, 4, 5, and so on...

Code: Select all

joyGetPosEx

The joyGetPosEx function queries a joystick for its position and button status.

MMRESULT joyGetPosEx(
  UINT uJoyID,     
  LPJOYINFOEX pji  
);

Parameters

uJoyID

Identifier of the joystick to be queried. Valid values for uJoyID range from zero (JOYSTICKID1) to 15, except for Windows NT 4.0. For Windows NT 4.0, valid values are limited to JOYSTICKID1 and JOYSTICKID2.
http://msdn.microsoft.com/library/defau ... tposex.asp

>force feedback

You are surely true because i don't see anything about that in the winmm.

I thought it was only possible to capture 2 of the 16 max joysticks (but use anyone of them).
but I think you're right, the 2 joysticks limitation should be just with NT.
Only two joysticks too, I can't test :roll:
Intrigued
Enthusiast
Enthusiast
Posts: 501
Joined: Thu Jun 02, 2005 3:55 am
Location: U.S.A.

Post by Intrigued »

#JOYCAPS_HASZ = 1
#JOYCAPS_HASR = 2
#JOYCAPS_HASU = 4
#JOYCAPS_HASV = 8
#JOYCAPS_HASPOV = 16
#JOYCAPS_POV4DIR = 32
#JOYCAPS_POVCTS = 64
What do these all mean?

TIA
Intrigued - Registered PureBasic, lifetime updates user
User avatar
Flype
Addict
Addict
Posts: 1542
Joined: Tue Jul 22, 2003 5:02 pm
Location: In a long distant galaxy

Post by Flype »

#JOYCAPS_HASZ = Does your controller have a 3rd axis
#JOYCAPS_HASR = Does your controller have a 4th axis
#JOYCAPS_HASU = Does your controller have a 5th axis
#JOYCAPS_HASV = Does your controller have a 6th axis
#JOYCAPS_HASPOV = Does your controller have a Point Of Vue
#JOYCAPS_POV4DIR = Does your Point Of Vue have 4 directions
#JOYCAPS_POVCTS = Does your Point Of Vue supports degrees

Please, see msdn:
http://msdn.microsoft.com/library/defau ... ps_str.asp
No programming language is perfect. There is not even a single best language.
There are only languages well suited or perhaps poorly suited for particular purposes. Herbert Mayer
User avatar
Flype
Addict
Addict
Posts: 1542
Joined: Tue Jul 22, 2003 5:02 pm
Location: In a long distant galaxy

Post by Flype »

here is an include for winmm.lib :

Code: Select all

; Subject: Joystick, Windows Multimedia API (Use debugger for error messages)
; Header:  Declared in mmsystem.h; include windows.h.
; Library: Use winmm.lib.

;{ Joystick: Constantes (Missing in PB)

#JOYCAPS_HASZ    = 1
#JOYCAPS_HASR    = 2
#JOYCAPS_HASU    = 4
#JOYCAPS_HASV    = 8
#JOYCAPS_HASPOV  = 16
#JOYCAPS_POV4DIR = 32
#JOYCAPS_POVCTS  = 64

#JOY_CONFIGCHANGED_MSGSTRING = "MSJSTICK_VJOYD_MSGSTR"

;}
;{ Joystick: Functions (Standard)

Procedure.l joyConfigChanged()
  
  ; The joyConfigChanged function informs the joystick driver that the
  ; Configuration has changed and should be reloaded from the registry.
  
  Select joyConfigChanged_(#Null) ; Reserved, must be null
    Case #JOYERR_PARMS
      Debug "An invalid parameter was passed."
    Case #JOYERR_NOERROR
      ProcedureReturn #True
  EndSelect
  
EndProcedure
Procedure.l joyGetDevCaps(joyID.l,*caps.JOYCAPS)
  
  ; The joyGetDevCaps function queries a joystick to determine its capabilities.
  
  Select joyGetDevCaps_(joyID,*caps,SizeOf(JOYCAPS))
    Case #MMSYSERR_NODRIVER
      Debug "The joystick driver is not present."
    Case #MMSYSERR_INVALPARAM
      Debug "An invalid parameter was passed."
    Case #JOYERR_NOERROR
      ProcedureReturn #True
  EndSelect
  
EndProcedure
Procedure.l joyGetNumDevs()
  
  ; The joyGetNumDevs function queries the joystick driver for the number of joysticks it supports.
  
  ProcedureReturn joyGetNumDevs_()
  
EndProcedure
Procedure.l joySetCapture(joyID.l,wndID.l)
  
  ; The joySetCapture function captures a joystick by causing its messages to be sent to the specified window.
  ; This function fails if the specified joystick is currently captured.
  ; Call the joyReleaseCapture function to release the captured joystick, or destroy the window to release the joystick automatically.
  
  fChanged.l = #False
  uPeriod.l = #Null ; ( wPeriodMin > uPeriod > wPeriodMax )
  
  Select joySetCapture_(WindowID(wndID),joyID,uPeriod,fChanged)
    Case #MMSYSERR_NODRIVER
     	Debug "The joystick driver is not present."
    Case #MMSYSERR_INVALPARAM
     	Debug "Invalid joystick ID or hwnd is NULL."
    Case #JOYERR_PARMS
     	Debug "Invalid joystick ID or hwnd is NULL."
    Case #JOYERR_NOCANDO
     	Debug "Cannot capture joystick input because a required service (such as a Windows timer) is unavailable."
    Case #JOYERR_UNPLUGGED
     	Debug "The specified joystick is not connected to the system."
    Case #JOYERR_NOERROR
      ProcedureReturn #True
  EndSelect

EndProcedure
Procedure.l joyReleaseCapture(joyID.l)
  
  ; The joyReleaseCapture function releases the specified captured joystick.
  
  Select joyReleaseCapture_(joyID)
    Case #MMSYSERR_NODRIVER
     	Debug "The joystick driver is not present."
    Case #MMSYSERR_INVALPARAM
     	Debug "The specified joystick has not been captured"
    Case #JOYERR_PARMS
     	Debug "The specified joystick device identifier is invalid."
    Case #JOYERR_NOERROR
      ProcedureReturn #True
  EndSelect
  
EndProcedure
Procedure.l joyGetPos(joyID.l,*info.JOYINFO)
  
  ; The joyGetPos function queries a joystick for its position and button status.
  ; For devices that have four to six axes of movement, a point-of-view control,
  ; Or more than four buttons, use the joyGetPosEx function.
  
  Select joyGetPos_(joyID,*info)
    Case #MMSYSERR_NODRIVER
      Debug "The joystick driver is not present."
    Case #MMSYSERR_INVALPARAM
      Debug "An invalid parameter was passed."
    Case #JOYERR_UNPLUGGED
      Debug "The specified joystick is not connected to the system."
    Case #JOYERR_NOERROR
      ProcedureReturn #True
  EndSelect
  
EndProcedure
Procedure.l joyGetPosEx(joyID.l,*info.JOYINFOEX)
  
  ; The joyGetPosEx function queries a joystick for its position and button status.
  ; This function provides access to extended devices such as rudder pedals,
  ; Point-of-view hats, devices with a large number of buttons, and coordinate systems using up to six axes.
  ; For joystick devices that use three axes or fewer and have fewer than four buttons, use the joyGetPos function.
  
  *info\dwSize = SizeOf(JOYINFOEX)
  *info\dwFlags = #JOY_RETURNALL
  
  Select joyGetPosEx_(joyID,*info)
    Case #MMSYSERR_NODRIVER
      Debug "The joystick driver is not present."
    Case #MMSYSERR_INVALPARAM
      Debug "An invalid parameter was passed."
    Case #MMSYSERR_BADDEVICEID
      Debug "The specified joystick identifier is invalid."
    Case #JOYERR_PARMS
      Debug "The specified joystick identifier is invalid."
    Case #JOYERR_UNPLUGGED
      Debug "The specified joystick is not connected to the system."
    Case #JOYERR_NOERROR
      ProcedureReturn #True
  EndSelect

EndProcedure
Procedure.l joyGetThreshold(joyID.l)
  
  ; The joyGetThreshold function queries a joystick for its current movement threshold.
  ; The threshold is initially zero.
  ; The movement threshold is the distance the joystick must be moved
  ; before a joystick position-change message is sent to a window that has captured the device.
  
  Select joySetThreshold_(joyID,@uThreshold.l)
    Case #MMSYSERR_NODRIVER
     	Debug "The joystick driver is not present."
    Case #MMSYSERR_INVALPARAM
     	Debug "An invalid parameter was passed."
    Case #JOYERR_NOERROR
      ProcedureReturn uThreshold
  EndSelect
  
EndProcedure
Procedure.l joySetThreshold(joyID.l,Threshold.l)
  
  ; The joySetThreshold function sets the movement threshold of a joystick.
  ; The threshold is initially zero.
  ; The movement threshold is the distance the joystick must be moved
  ; before a joystick position-change message is sent to a window that has captured the device.
  
  Select joySetThreshold_(joyID,Threshold)
    Case #MMSYSERR_NODRIVER
      Debug "The joystick driver is not present."
    Case #JOYERR_PARMS
      Debug "The specified joystick identifier is invalid."
    Case #JOYERR_NOERROR
      ProcedureReturn #True
  EndSelect
  
EndProcedure

;}
;{ Joystick: Functions (Custom)

Procedure.l joyRegister()
  
  ; This message may be defined by applications that need to respond to changes in
  ; Joystick calibration by using RegisterWindowMessage with the following message ID.
  
  ProcedureReturn RegisterWindowMessage_(#JOY_CONFIGCHANGED_MSGSTRING)
  
EndProcedure

;}
and here an example:

Code: Select all

XIncludeFile "winmm_joystick.pb"

Macro HEAD2(y,a)
  DrawingFont(FontID(1))
  DrawText(x,y,a,TextColor)
  DrawingFont(FontID(0))
EndMacro
Macro TEXT2(y,a,b)
  DrawText(2+DrawText(x,y,a,TextColor),y,b,RGB(0,0,0))
EndMacro

Procedure.l Update(*caps.JOYCAPS, *info.JOYINFOEX)
  
  TextColor = $F0F0F0
  LineColor = $966E47
  FrontColor = $A77F58
  ButtonColor = $193CC0
  
  iw = ImageWidth(0)
  ih = ImageHeight(0)
  
  iw2 = iw - 50
  ih2 = ih - 50
  
  x = (*info\dwXpos * iw2) / (*caps\wXmax)
  y = (*info\dwYpos * ih2) / (*caps\wYmax)
  w = (*info\dwRpos * iw2) / (*caps\wRmax)
  h = (*info\dwZpos * ih2) / (*caps\wZmax)
  
  StatusBarText(0,0,Str(x))
  StatusBarText(0,1,Str(y))
  StatusBarText(0,2,Str(w))
  StatusBarText(0,3,Str(h))
  StatusBarText(0,4,RSet(Bin(*info\dwButtons),32,"0"))
  
  If StartDrawing(ImageOutput(0))
    
    DrawingMode(1)
    DrawingFont(FontID(0))
    
    Box(0,0,iw,ih,FrontColor)
    Box(25,25,iw2,ih2,LineColor)
    Line(iw/2-2,0,0,ih,TextColor)
    Line(0,ih/2-2,iw,0,TextColor)
    Line(x+25,0,0,ih,0)
    Line(0,y+25,iw,0,0)
    Ellipse(25+x,25+y,w/2,h/2,0)
    Ellipse(25+x,25+y,(w/2)-1,(h/2)-1,FrontColor)
    Line(x+25,y+25-(h/2),0,h,LineColor)
    Line(x+25-(w/2),y+25,w,0,LineColor)
    
    y = 15
    For i = 0 To (*caps\wMaxButtons-1)
      If (i % 5) = 0
        x = iw - 165 : y + 25
      EndIf
      x + 25
      Circle(x,y,12,FrontColor)
      If (*info\dwButtons & (1<<i))
        Circle(x,y,10,ButtonColor)
      Else
        Circle(x,y,11,LineColor)
      EndIf
      If (i<*caps\wNumButtons)
        DrawText(x-7,y-6,RSet(Str(i+1),2,"0"),TextColor)
      Else
        DrawText(x-7,y-6,RSet(Str(i+1),2,"0"),FrontColor)
      EndIf
    Next
    
    x=10 : y=10
    HEAD2(y,"Device Informations")
    TEXT2(y+15,"Name:",   PeekS(@*caps\szPname))
    TEXT2(y+30,"Manufac:","0x"+Hex(*caps\wMid))
    TEXT2(y+45,"Product:","0x"+Hex(*caps\wPid))
    TEXT2(y+60,"RegKey:", PeekS(@*caps\szRegKey))
    TEXT2(y+75,"OEMVxD:", PeekS(@*caps\szOEMVxD))
    
    x=10 : y=120
    HEAD2(y,"Device Capabities")
    TEXT2(y+15, "Axis:",   Str(*caps\wNumAxes)+" On "+Str(*caps\wMaxAxes))
    TEXT2(y+30, "Period:", Str(*caps\wPeriodMin)+" To "+Str(*caps\wPeriodMax)+" ms")
    TEXT2(y+45, "HasZ:",   Str((*caps\wCaps&#JOYCAPS_HASZ)/#JOYCAPS_HASZ))
    TEXT2(y+60, "HasR:",   Str((*caps\wCaps&#JOYCAPS_HASR)/#JOYCAPS_HASR))
    TEXT2(y+75, "HasU:",   Str((*caps\wCaps&#JOYCAPS_HASU)/#JOYCAPS_HASU))
    TEXT2(y+90, "HasV:",   Str((*caps\wCaps&#JOYCAPS_HASV)/#JOYCAPS_HASV))
    TEXT2(y+105,"HasPOV:", Str((*caps\wCaps&#JOYCAPS_HASPOV)/#JOYCAPS_HASPOV))
    TEXT2(y+120,"POV4DIR:",Str((*caps\wCaps&#JOYCAPS_POV4DIR)/#JOYCAPS_POV4DIR))
    TEXT2(y+135,"POVCTS:", Str((*caps\wCaps&#JOYCAPS_POVCTS)/#JOYCAPS_POVCTS))
    
    x=iw-150 : y=10
    HEAD2(y,"Buttons State")
    
    x=iw-150 : y=ih-160
    HEAD2(y,"Point Of Vue")
    TEXT2(y+15,"State:",Str(*info\dwPOV))
    
    x=iw-150 : y=ih-110
    HEAD2(y,"Axis State")
    TEXT2(y+ 15,"Axis X:",RSet(Str(*info\dwXpos),5,"0")+" ("+Str(*caps\wXmin)+","+Str(*caps\wXmax)+")")
    TEXT2(y+ 30,"Axis Y:",RSet(Str(*info\dwYpos),5,"0")+" ("+Str(*caps\wYmin)+","+Str(*caps\wYmax)+")")
    TEXT2(y+ 45,"Axis Z:",RSet(Str(*info\dwZpos),5,"0")+" ("+Str(*caps\wZmin)+","+Str(*caps\wZmax)+")")
    TEXT2(y+ 60,"Axis R:",RSet(Str(*info\dwRpos),5,"0")+" ("+Str(*caps\wRmin)+","+Str(*caps\wRmax)+")")
    TEXT2(y+ 75,"Axis U:",RSet(Str(*info\dwUpos),5,"0")+" ("+Str(*caps\wUmin)+","+Str(*caps\wUmax)+")")
    TEXT2(y+ 90,"Axis V:",RSet(Str(*info\dwVpos),5,"0")+" ("+Str(*caps\wVmin)+","+Str(*caps\wVmax)+")")
    
    StopDrawing()
    
    SetGadgetState(0,ImageID(0))
    
  EndIf
 
EndProcedure
Procedure.l Main(joyId.l,width.l,height.l)
  
  flags = #PB_Window_SystemMenu
  flags | #PB_Window_MinimizeGadget
  flags | #PB_Window_MaximizeGadget
  flags | #PB_Window_SizeGadget
  flags | #PB_Window_ScreenCentered
  
  If OpenWindow(0,0,0,width,height,flags,"winmm.lib: joystick functions.")
    
    If CreateStatusBar(0,WindowID(0))
      AddStatusBarField(30)
      AddStatusBarField(30)
      AddStatusBarField(30)
      AddStatusBarField(30)
      AddStatusBarField(220)
      AddStatusBarField($fff)
      StatusBarText(0,5,"Number of joysticks supported by the driver: "+Str(joyGetNumDevs()))
    EndIf
    
    If CreateGadgetList(WindowID(0))
      CreateImage(0,width,height)
      ImageGadget(0,0,0,width,height,0)
    EndIf
    
    LoadFont(0,"Verdana",7,#PB_Font_HighQuality)
    LoadFont(1,"Verdana",7,#PB_Font_Underline|#PB_Font_Bold)
    
    joySetCapture(joyId,0)
    joyGetDevCaps(joyId,joyCaps.JOYCAPS)
    joyGetPosEx(joyId,joyInfo.JOYINFOEX)
    
    Repeat
      
      Select WaitWindowEvent(50)
        Case #PB_Event_CloseWindow
          Break
        Case #PB_Event_SizeWindow
          ResizeImage(0,WindowWidth(0),WindowHeight(0)-StatusBarHeight(0),#PB_Image_Raw)
      EndSelect
      
      If joyGetPosEx(joyId,joyInfo)
        Update(joyCaps,joyInfo)
      EndIf
      Delay(1)
      
    ForEver
    
    joyReleaseCapture(joyId)
    
  EndIf
  
EndProcedure

Main(#JOYSTICKID1,640,400)
No programming language is perfect. There is not even a single best language.
There are only languages well suited or perhaps poorly suited for particular purposes. Herbert Mayer
Intrigued
Enthusiast
Enthusiast
Posts: 501
Joined: Thu Jun 02, 2005 3:55 am
Location: U.S.A.

Post by Intrigued »

Thanks Flype! On both accounts.
Intrigued - Registered PureBasic, lifetime updates user
SFSxOI
Addict
Addict
Posts: 2970
Joined: Sat Dec 31, 2005 5:24 pm
Location: Where ya would never look.....

Post by SFSxOI »

Very nice! Thank You very much.

I've often wondered why tho that the joystick is included under multimedia in windows? Oh well...

Now if someone who does Direct Input could do something for the mouse.... :)
Post Reply