Accessing+two+joysticks

//by Richard Russell, April 2007//

The BBC BASIC [|ADVAL] statement allows you to access only one joystick. If you need to access two joysticks you can do that using the **Windows API**. The procedure below allows you to read the **X**, **Y**, **Z** and **button** values for either joystick:

code format="bb4w" DEF PROCjoystick(id%, RETURN x%, RETURN y%, RETURN z%, RETURN b%) LOCAL joyinfo{} DIM joyinfo{wXpos%, wYpos%, wZpos%, wButtons%} SYS "joyGetPos", id%, joyinfo{} x% = joyinfo.wXpos% y% = joyinfo.wYpos% z% = joyinfo.wZpos% b% = joyinfo.wButtons% ENDPROC code To access the first joystick set the first parameter **id%** to **0**; to access the second joystick set **id%** to **1**.

You would call the procedure using code similar to the following:

code format="bb4w" PROCjoystick(0, x1%, y1%, z1%, buttons1%) PROCjoystick(1, x2%, y2%, z2%, buttons2%) code This will load the current joystick values into the specified variables.