User Tools

Site Tools


accessing_20two_20joysticks

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%
        ENDPROC

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. By using the website, you agree with storing cookies on your computer. Also you acknowledge that you have read and understand our Privacy Policy. If you do not agree leave the website.More information about cookies
accessing_20two_20joysticks.txt · Last modified: 2024/01/05 00:22 by 127.0.0.1