Pub.FreeJoy: Functions Modinfo Source  

Joystick

The BlitzMax freejoy module contains commands that report the status of any joysticks and game controllers connected to the system.

Functions

Function JoyAxisCaps(port)
ReturnsA bitfield representing which axis are available.
DescriptionAvailable axis (proportional controls) on a joystick.

Function JoyButtonCaps(port)
ReturnsA bitfield representing which buttons are present.
DescriptionAvailable buttons (on/off controls) on a joystick.

Function JoyCount()
ReturnsThe number of joysticks and gamecontrollers connected to the system.
DescriptionCounts the number of joysticks.
Example
' testjoy.bmx

Import Pub.FreeJoy

Strict

If Not JoyCount() RuntimeError "No joystick found!"

Graphics 640,480

Function drawprop(n$,p#,y)
	Local	w
	DrawText n$,0,y
	w=Abs(p)*256
	If p<0
		DrawRect 320-w,y,w,16
	Else
		DrawRect 320,y,w,16
	EndIf
End Function		

Local t=0

While Not KeyHit(KEY_ESCAPE)
	Cls
	
	SetColor 255,255,255
	Local n=JoyCount()
	DrawText "joycount="+n,0,0
	DrawText "JoyName(0)="+JoyName(0),0,20
	DrawText "JoyButtonCaps(0)="+Bin$(JoyButtonCaps(0)),0,40
	DrawText "JoyAxisCaps(0)="+Bin$(JoyAxisCaps(0)),0,60

	For Local i=0 To 31
		SetColor 255,255,255
		If JoyDown(i) SetColor 255,0,0
		DrawOval i*16,80,14,14
	Next
	
	SetColor 255,255,0
	drawprop "JoyX=",JoyX(0),100
	drawprop "JoyY:",JoyY(0),120
	drawprop "JoyZ:",JoyZ(0),140
	drawprop "JoyR:",JoyR(0),160
	drawprop "JoyU:",JoyU(0),180
	drawprop "JoyV:",JoyV(0),200
	drawprop "JoyHat:",JoyHat(0),220
	drawprop "JoyWheel:",JoyWheel(0),240
	
	DrawRect 0,280,t,10
	t=(t+1)&511
	
	Flip	
Wend

End

Function JoyDown( button,port=0 )
ReturnsTrue if the button is pressed.
DescriptionTest the status of a joystick button.

Function JoyHat#( port=0 )
Returns-1.0 if the joystick is centered, and values between 0.0, 0.25, 0.5.
DescriptionReports the position of the joystick's HAT controller if supported.

Function JoyHit( button,port=0 )
ReturnsNumber of times button has been hit.
DescriptionCheck for a joystick button press.
InformationThe returned value represents the number of the times button has been hit since the last call to JoyHit with the same specified button.

Function JoyName$(port)
ReturnsThe system name of the joystick.
DescriptionGet the name of the joysticks connected to the specified port.

Function JoyPitch#( port=0 )
ReturnsZero if the joystick is centered, -1.0 if Up, 1.0 if Down or a value inbetween.
DescriptionReports the position of the joystick's PITCH axis if supported.

Function JoyR#( port=0 )
ReturnsZero if the joystick is centered, -1.0 if Up, 1.0 if Down or a value inbetween.
DescriptionReports the position of the joystick's R axis if supported.

Function JoyRoll#( port=0 )
ReturnsZero if the joystick is centered, -1.0 if Up, 1.0 if Down or a value inbetween.
DescriptionReports the position of the joystick's ROLL axis if supported.

Function JoyU#( port=0 )
ReturnsZero if the joystick is centered, -1.0 if Up, 1.0 if Down or a value inbetween.
DescriptionReports the position of the joystick's U axis if supported.

Function JoyV#( port=0 )
ReturnsZero if the joystick is centered, -1.0 if Up, 1.0 if Down or a value inbetween.
DescriptionReports the position of the joystick's V axis if supported.

Function JoyWheel#( port=0 )
ReturnsZero if the joystick is centered, -1.0 if Left, 1.0 if Right or a value inbetween.
DescriptionReports the position of the joystick's YAW axis if supported.

Function JoyX#( port=0 )
ReturnsZero if the joystick is centered, -1 if Left, 1 if Right or a value inbetween.
DescriptionReports the horizontal position of the joystick.

Function JoyY#( port=0 )
ReturnsZero if the joystick is centered, -1.0 if Up, 1.0 if Down or a value inbetween.
DescriptionReports the vertical position of the joystick.

Function JoyYaw#( port=0 )
ReturnsZero if the joystick is centered, -1.0 if Up, 1.0 if Down or a value inbetween.
DescriptionReports the position of the joystick's YAW axis if supported.

Function JoyZ#( port=0 )
ReturnsZero if the joystick is centered, -1.0 if Up, 1.0 if Down or a value inbetween.
DescriptionReports the position of the joystick's Z axis if supported.

Module Information

Version1.08
AuthorSimon Armstrong
LicensePublic Domain
CopyrightBlitz Research Ltd
ModserverBRL
History1.08 Release
HistoryAdded JoyHit samplejoy fix, thanks to HamishTheHystericalHamster
History1.07 Release
HistoryAdded MacOSX Rx,Ry,Rz (JoyR,JoyU,JoyV) and Wheel
History1.06 Release
HistoryEnabled Apple Gamepad and MultiAxis HID classes
History1.05 Release
HistoryFixed Linux C Compiler warnings
History1.04 Release
HistoryFixed C Compiler warnings