'joypos.bas
'Bare bones joystick demo
'prints out x,y,z position
'and buttons pressed.
'from Mastering LB3 eBook
'http://alycesrestaurant.com/master.htm
'
'NOTE: You must have an appropriate game controller driver
'installed for this program to do anything!

nomainwin

    Struct JOYINFO, _
        x As long , _   'x position
        y As long , _   'y position
        z As long , _   'z position
        buttons As long 'buttons pushed

JOYSTICK1 = 0
JOYSTICK2 = 1

UpperLeftX=10:UpperLeftY=10
WindowWidth=600:WindowHeight=450
statictext #1.x, "X",10,10,100,24
statictext #1.y, "Y",10,40,100,24
statictext #1.z, "Z",10,70,100,24
statictext #1.1, "1",10,100,100,24
statictext #1.2, "2",10,130,100,24

Open "Joystick Demo" for window_nf as #1
print #1, "trapclose [quit]"

timer 150, [checkJoy]

[loop]
    wait

[quit]
    close #1 : END


[checkJoy]
    calldll #winmm,  "joyGetPos", _
        JOYSTICK1 as long, _
        JOYINFO as struct ,_
        result as long

    X = JOYINFO.x.struct
    Y = JOYINFO.y.struct
    Z = JOYINFO.z.struct

    b1 = JOYINFO.buttons.struct and 1
    b2 = JOYINFO.buttons.struct and 2

    print #1.x, "X - ";X
    print #1.y, "Y - ";Y
    print #1.z, "Z - ";Z

    if b1 then
        print #1.1, "Button 1 - down"
    else
        print #1.1, "Button 1 - up"
    end if

    if b2 then
        print #1.2, "Button 2 - down"
    else
        print #1.2, "Button 2 - up"
    end if

    goto [loop]
