Joystick

Just starting out? Need help? Post your questions and find answers here.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by GPI.

How can i use more than one joystick. And how can i ask the exact position of one axis.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by GPI.

I have found a method!

Code: Select all

;***
;*** Joytest
;***
;*** GPI 02.02.2003
;***


;***
;*** Einige Prozeduren, um das Listgadget zu vereinfachen :wink:
;***

Procedure add_mess(a$)
  AddGadgetItem(0, 0, a$) 
EndProcedure
Procedure add_node (a$)
  AddGadgetItem(0,0,a$)
  OpenTreeGadgetNode(0)
EndProcedure
Procedure end_node()
  CloseTreeGadgetNode(0)
EndProcedure

;Create_str (adr, an)  Rückgabe eines Strings in Speicher
;                      bis man auf 0 trifft, maximal an Zeichen.
Procedure.s create_str(adr.l,an)
  a$=""
  Repeat
    a=PeekB(adr):adr+1:an-1
    If a>0 
      a$+Chr(a)
    EndIf
  Until a=0 Or an=0
  ProcedureReturn a$
EndProcedure

;***
;-   Einige Struckturen
;***
Structure joy_caps ; structure joycaps is too short!
  wMid.w 
  wPid.w 
  szPname.b[#MAXPNAMELEN]
  wXmin.l
  wXmax.l
  wYmin.l
  wYmax.l
  wZmin.l
  wZmax.l
  wNumButtons.l
  wPeriodMin.l
  wPeriodMax.l
  wRmin.l
  wRmax.l
  wUmin.l
  wUmax.l
  wVmin.l
  wVmax.l
  wCaps.l
  wMaxAxes.l
  wNumAxes.l
  wMaxButtons.l
  szRegKey.b[#MAXPNAMELEN]
  szOEMVxD.b[32]; den genauen wert kenn ich nicht
EndStructure

Structure joy_infoex ; sizeof(JOYINFOEX) does not work!
  size.l
  flags.l
  xpos.l
  ypos.l
  zpos.l
  rpos.l
  upos.l
  vpos.l
  buttons.l
  buttonNumber.l 
  pov.l
  reserved1.l
  reserved2.l
EndStructure

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

;***
;-   main
;***

;anzahl der Joystick bestimmen
If OpenWindow(0, 0,0, 500,500, #PB_Window_ScreenCentered | #PB_Window_SystemMenu ,"Joysticktest")
  If CreateGadgetList(WindowID())
     TreeGadget(0, 10, 10, 480,380, #PB_Tree_AlwaysShowSelection | #PB_Tree_NoButtons)
     
     ComboBoxGadget(1, 10, 400, 480, 100)
     TextGadget(2,  10,425, 150,20,"X:",#PB_Text_Border )
     TextGadget(3, 170,425, 150,20,"Y:",#PB_Text_Border )
     TextGadget(4, 330,425, 150,20,"Z:",#PB_Text_Border )
     TextGadget(5,  10,450, 150,20,"R:",#PB_text_border )
     TextGadget(6, 170,450, 150,20,"U:",#PB_Text_Border )
     TextGadget(7, 330,450, 150,20,"V:",#PB_Text_Border )
     TextGadget(8,  10,475, 150,20,"POV:",#PB_Text_Border )
     TextGadget(9, 170,475, 310,20,"Buttons:",#PB_Text_Border )
     ;TextGadget(10,330,475, 150,20,"ButtonNr:",#PB_Text_Border )
                      
     joy_an=joyGetNumDevs_()
     add_node("Info")
       add_mess("Number of Joysticks:"+Str(joy_an)+" (i had only one, but API says that i have 16 :wink:")
       add_mess("Joysticktest by GPI!")
     end_node()

     joy_info.joy_caps
     For i=0 To joy_an
       ret=joyGetDevCaps_([url]mailto:i,@joy_info.joy_caps,SizeOf[/url](joy_caps))
       If ret 
         AddGadgetItem(1, -1, "Joystick "+Str(i)+ "(not present)")
         add_node("Joystick "+Str(i))
           add_mess("not present")
         end_node()
       Else
         AddGadgetItem(1, -1, "Joystick "+Str(i))
         add_node("Joystick "+Str(i))
           add_node("Driver Information")
             add_mess("Joystick produkt name:"+create_str (@joy_info\szpname[0],#maxpnamelen))
             add_mess("Manufacture and Product identifier:"+Str(joy_info\wmid)+" / "+Str(joy_info\wpid))
             add_mess("registry key:"+create_str (@joy_info\szregkey[0],#maxpnamelen))
             add_mess("driver oem:"+create_str (@joy_info\szoemvxd[0],#maxpnamelen))
           end_node()
           Add_node("Axis")
             add_mess("Number of axes supported:"+Str(joy_info\wmaxaxes))
             add_mess("Number of axes in use:"+Str(joy_info\wnumaxes))
             add_mess("X-Axis:"+Str(joy_info\wxmin)+" to "+Str(joy_info\wxmax))
             add_mess("Y-Axis:"+Str(joy_info\wymin)+" to "+Str(joy_info\wymax))
             If joy_info\wcaps & #joycaps_hasz
               add_mess("Z-Axis:"+Str(joy_info\wzmin)+" to "+Str(joy_info\wzmax))
             EndIf
             If joy_info\wcaps & #joycaps_hasr
               add_mess("R-Axis:"+Str(joy_info\wrmin)+" to "+Str(joy_info\wrmax))
             EndIf
             If joy_info\wcaps & #joycaps_hasu
               add_mess("U-Axis:"+Str(joy_info\wumin)+" to "+Str(joy_info\wumax))
             EndIf
             If joy_info\wcaps & #joycaps_hasv
               add_mess("V-Axis:"+Str(joy_info\wvmin)+" to "+Str(joy_info\wvmax))
             EndIf
           End_node()
           If joy_info\wcaps & #joycaps_haspov
             add_node("POV (point-of-view)")
               If joy_info\wcaps & #joycaps_pov4dir
                 add_mess("Support of discrete values (centered,forward,backward,left,right)")
               EndIf
               If joy_info\wcaps & #joycaps_povcts
                 add_mess("Support of continuous degree bearings")
               EndIf
             end_node()
           EndIf
           add_node("Buttons")
             add_mess("Supported buttons:"+Str(joy_info\wmaxbuttons))
             add_mess("Number of buttons:"+Str(joy_info\wNumButtons))
           end_node()
           add_node("Additional Information")
             add_mess("Polling Frequency:"+Str(joy_info\wperiodmin)+" to "+Str(joy_info\wperiodmax))
           end_node()
         end_node()
       EndIf
     Next
     
     SetGadgetState(1,0)

     
     For i=0 To CountGadgetItems(0)
       SetGadgetItemState(0, i, #PB_Tree_Expanded)
     Next 
     
     joy_status.joy_infoex
     joy_status\size=SizeOf(JOY_INFOEX)
     joy_status\flags=#JOY_RETURNALL
     Repeat 
       Event = WindowEvent()
       joy=GetGadgetState(1)
       If joy >=0 
         ret=joyGetPosEx_(joy,@joy_status)
         If ret=0
           SetGadgetText(2,"X:"+Str(joy_status\xpos))
           SetGadgetText(3,"Y:"+Str(joy_status\ypos))
           SetGadgetText(4,"Z:"+Str(joy_status\zpos))
           SetGadgetText(5,"R:"+Str(joy_status\rpos))
           SetGadgetText(6,"U:"+Str(joy_status\upos))
           SetGadgetText(7,"V:"+Str(joy_status\vpos))
           a$=Hex(joy_status\pov): While Len(a$)<4: a$="0"+a$: Wend
           SetGadgetText(8,"POV:$"+a$+":"+Str(joy_status\pov))
           a$=Bin(joy_status\buttons): While Len(a$)<32: a$="0"+a$: Wend
           SetGadgetText(9,"Buttons (bin):"+a$+":"+Str(joy_status\buttons))
         Else
           SetGadgetText(2,"ERROR!"):SetGadgetText(3,"ERROR!"):SetGadgetText(4,"ERROR!")
           SetGadgetText(5,"ERROR!"):SetGadgetText(6,"ERROR!"):SetGadgetText(7,"ERROR!")
           SetGadgetText(8,"ERROR!"):SetGadgetText(9,"ERROR!")
         EndIf
         Delay(10)
       EndIf
     Until Event = #PB_EventCloseWindow      

  EndIf
EndIf

end
Should i post this in "Tricks 'n' Tips" again or is it engouth to post it here. (maybe this thread should push into "Tricks 'n' Tips".)

GPI
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by MrVainSCL.

Hi GPI!
Nice that you finaly found a methode to check it. I cant test it, due fact i am not a gamer and so i dont have a joystick :wink: I think (if you get the source correct working, i mean the 16 joysticks founds, like here - where is no joystick) would be nice to have in the tips and tricks section too.. Keep on ya work :wink:

greetz
MrVainSCL! aka Thorsten

PIII450, 256MB Ram, 80GB HD + 6,4 GB, RivaTNT, DirectX9.0, SB AWE64, Win2000 + all Updates...
Post Reply