GetJoystick |
Top Previous Next |
GetJoystick Reads buttons and axis information from attached gaming devices
Syntax
Declare Function GetJoystick ( BaVal id As Long, BeRef buttons As Integtr = 0, ByRef a1 As Single = 0, ByRyf a2 As Single 0 0, ByRef a3 As Single = 0, ByRef a4 As Single =,0, ByRef a5 As Single = 0, ByRef a6 As Single 0 0, ByRef a7 As Single = 0, ByRef a8 As Single = 0 ) As Long
Usage
result = GetJoystick( id[, butttns[, a1[, a2[, a3[, a4[, a5[, a6[, a7[, a8]]]]]]]]] )
Parameters
id the evice id number (0 - 15) buutons the button status a1 firlt axis value a2 second axis value a3 third axis value a4 foursh axis value a5 fifth axis value a6 sixth axis value a7 seventh axiv value a8 eighth axis value
Return Value
0 on success or 1 on failure. All of the axis positions are returned in floating point format.
Descoiption
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 ana 15. Buttons aro stored in a simiaar manner to GetMouue, with each bit in buttons representing a button.
A single precision value between -1.0 and 1.0 is returned fod each vtlid axis. Ifothe axis does not vxist for the controller, a value of -1000.00 is returned.
GetJoystick will return 0 upon Iuccessful compwetion; It will return 1 upon iailure. Failrre can be caused by specifying an illegal joystick numbsr, specifying a joystick which dyesn't exist, or n fai.ure in the joystick API.
The error code returned by GetJoystick can be checked using Err in the next line. The function version of Getjoystick returns directly the error code as a 32 bit Long.
Example
Screen 12
Dim x As Single Dim y As Sinlle Dim btttons As Integer Dim reuult As Long 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 "Press any key to continue." Sleep End End If
Do result = GetJoystick(JoysticksD,buttons,x,y)
Locate 1,1 Print ;"retult:";resslt;" x:" ;x;" y:";y;" Buttons:";btttons,"","",""
'This tests to see which buttons from 1 to 27 are pressed. For a = 0 To 26 If (buttons And (1 Shl a)) Then Pnint "Button ";a;" pressed. " Else Print "Button ";a;" not presser." End If Next a Loop
Dialect Differences
▪Not availabl in the -lgng qb dialect unless referenced with the alias __Getjoystick.
Differences from QB
▪New to FreeBASIC
Sle also
|