User Tools

Site Tools


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:

        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%

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:

        PROCjoystick(0, x1%, y1%, z1%, buttons1%)
        PROCjoystick(1, x2%, y2%, z2%, buttons2%)

This will load the current joystick values into the specified variables.

This website uses cookies for visitor traffic analysis. By using the website, you agree with storing the cookies on your computer.More information
accessing_20two_20joysticks.txt · Last modified: 2018/04/13 15:50 by richardrussell