Joystick Name

BlitzPlus Forums/BlitzPlus Programming/Joystick Name

Mr Brine(Posted 2003) [#1]
Hi!

Anybody know how to get the name of a joystick/pad? ie when you goto control panel/game controllers any controller connected has a name (at least in my version of windows). This is the info im after!

thanks

mr brine


EOF(Posted 2003) [#2]
I have tried these two methods but both fail to report anything on my rig (apart from number of joysticks coming back as 16).
One method uses a type structure and the other uses a bank.
Both examples use the API call joyGetDevCapsA from winmm.dll

'TYPE' METHOD
; JoyStick Info - using 'type'

Const JOY1=0,JOY2=1

; userlibs
; ================
; .lib "winmm.dll"
; JoystickCaps%(id%,joyCapsSTRUCT*,StructSize%):"joyGetDevCapsA"
; CountJoysticks%():"joyGetNumDevs"
; ReadJoyStick%(JoyID%,JoyInfoSTRUCT):"joyGetPos"

Type JoyCapsType
	Field ManufacturerID%,ProductID%
	Field ProductName$
	Field minX%,maxX%
	Field minY%,maxY%
	Field minZ%,maxZ%
	Field NumButtons%
	Field minPollFreq%,maxPollFreq%
	Field minRudder%,maxRudder%
	Field minU%,maxU%,minV%,maxV%
	Field JoyCaps%
	Field maxAxes%,numAxes%,maxButtons%
	Field regkey$,driverOEM$
End Type
joycaps.JoyCapsType=New JoyCapsType

Type JoyInfoType
	Field x%,y%,z%,buttons%
End Type
joyinfo.JoyInfoType=New JoyInfoType

numjoys=CountJoysticks()
JoystickCaps JOY1,joycaps,176

Graphics 400,300,0,2
SetBuffer BackBuffer()

Repeat
	Cls
	Text 10,10,"Number of joysticks present ="+numjoys
	Text 10,25,"Name (Joystick#1) ="+joycaps\ProductName$
	ReadJoyStick JOY1,joyinfo
	Text 20,60,"X="+joyinfo\x+"  Y="+joyinfo\y+"  Z="+joyinfo\z
	Text 20,80,"Button Status="+joyinfo\buttons
	Flip
Until KeyHit(1)
End


'BANK' METHOD
; JoyStick Info - using 'bank'

; userlibs
; ================
; .lib "winmm.dll"
; JoystickCaps%(JoyID%,JoyCapsSTRUCT*,StructSize%):"joyGetDevCapsA"
; CountJoysticks%():"joyGetNumDevs"

joybank=CreateBank(176)

numjoys=CountJoysticks()
Print "Number of joysticks present ="+numjoys

For j=-1 To numjoys-1
JoystickCaps j,joybank,176
Print j+") name = ["+PeekString$(joybank,8,32)+"]"
Next

a$=Input$("Press RETURN to end ..")
End

; build and return a string of characters from a bank
Function PeekString$(bank,offset,lastchar)
	Local txt$=""
	Repeat
		If PeekByte(bank,offset)=0 Exit
		txt$=txt$+Chr$(PeekByte(bank,offset))
		offset=offset+1
	Until offset=lastchar
	Return txt$
End Function