{{fbdoc item="title" value="GETJOYSTICK"}}----
Reads buttons and axis information from attached gaming devices

{{fbdoc item="syntax"}}##
	[[KeyPgDeclare|declare]] [[KeyPgFunction|function]] **Getjoystick** ( [[KeyPgByval|byval]] //id// [[KeyPgAs|as]] [[KeyPgLong|long]], [[KeyPgByref|byref]] //buttons// [[KeyPgAs|as]] [[KeyPgInteger|integer]] = 0, [[KeyPgByref|byref]] //a1// [[KeyPgAs|as]] [[KeyPgSingle|single]] = 0, [[KeyPgByref|byref]] //a2// [[KeyPgAs|as]] [[KeyPgSingle|single]] = 0, [[KeyPgByref|byref]] //a3// [[KeyPgAs|as]] [[KeyPgSingle|single]] = 0, [[KeyPgByref|byref]] //a4// [[KeyPgAs|as]] [[KeyPgSingle|single]] = 0, [[KeyPgByref|byref]] //a5// [[KeyPgAs|as]] [[KeyPgSingle|single]] = 0, [[KeyPgByref|byref]] //a6// [[KeyPgAs|as]] [[KeyPgSingle|single]] = 0, [[KeyPgByref|byref]] //a7// [[KeyPgAs|as]] [[KeyPgSingle|single]] = 0, [[KeyPgByref|byref]] //a8// [[KeyPgAs|as]] [[KeyPgSingle|single]] = 0 ) [[KeyPgAs|as]] [[KeyPgInteger|integer]]
##
{{fbdoc item="usage"}}##
	//result// = **Getjoystick**( //id//[, //buttons//[, //a1//[, //a2//[, //a3//[, //a4//[, //a5//[, //a6//[, //a7//[, //a8//]]]]]]]]] )
##
{{fbdoc item="param"}}
	##//id//##
		the device id number (0 - 15)
	##//buttons//##
		the button status
	##//a1//##
		first axis value
	##//a2//##
		second axis value
	##//a3//##
		third axis value
	##//a4//##
		fourth axis value
	##//a5//##
		fifth axis value
	##//a6//##
		sixth axis value
	##//a7//##
		seventh axis value
	##//a8//##
		eighth axis value

{{fbdoc item="ret"}}
	##0## on success or ##1## on failure.  All of the axis positions are returned in floating point format.

{{fbdoc item="desc"}}
	##**Getjoystick**## will retrieves the button state, and the axis positions for up to 8 axes, for the joystick determined by ##//id//##, a number between ##0## and ##15##. Buttons are stored in a similar manner to ##[[KeyPgGetmouse|Getmouse]]##, with each bit in ##//buttons//## representing a button.
	
	A single precision value between ##-1.0## and ##1.0## is returned for each valid axis.  If the axis does not exist for the controller, a value of ##-1000.00## is returned.
	
	##**Getjoystick**## will return ##0## upon successful completion; It will return ##1## upon failure. Failure can be caused by specifying an illegal joystick number, specifying a joystick which doesn't exist, or a failure in the joystick API.
	
	The error code returned by ##**Getjoystick**## can be checked using ##[[KeyPgErr|Err]]## in the next line. The function version of  ##Getjoystick## returns directly the error code as a 32 bit ##[[KeyPgLong|Long]]##.

{{fbdoc item="ex"}}
{{fbdoc item="filename" value="examples/manual/input/getjoystick.bas"}}%%(freebasic)
screen 12

dim x as single
dim y as single
dim buttons as integer
dim result as integer
dim a as integer

const JoystickID = 0

'This line checks to see if the joystick is ok.

if GETJOYSTICK(JoystickID,buttons,x,y) then 
	print "Joystick doesn't exist or joystick error."
	print
	print "Press any key to continue."
	sleep
	end
end if


do
	result = GETJOYSTICK(JoystickID,buttons,x,y)

	locate 1,1
	print ;"result:";result;" x:" ;x;" y:";y;" Buttons:";buttons,"","",""
	
	'This tests to see which buttons from 1 to 27 are pressed. 
	for a = 0 to 26 
		if (buttons AND (1 shl a)) then 
			print "Button ";a;" pressed.    "
		else 
			print "Button ";a;" not pressed."
		end if
	next a
loop
%%

{{fbdoc item="lang"}}
	- Not available in the //[[CompilerOptlang|-lang qb]]// dialect unless referenced with the alias ##**""__Getjoystick""**##.

{{fbdoc item="diff"}}
	- New to ""FreeBASIC""

{{fbdoc item="see"}}
	- ##[[KeyPgScreengraphics|Screen (Graphics)]]##
	- ##[[KeyPgSetmouse|Setmouse]]##
	- ##[[KeyPgGetmouse|Getmouse]]##
	- ##[[KeyPgMultikey|Multikey]]##
	- ##[[KeyPgEvent|Event]]##
	- ##[[KeyPgScreenevent|ScreenEvent]]##

{{fbdoc item="back" value="CatPgGfxInput|User Input Functions"}}