Jump to content

Not Getting Joystick buttons


Ejoc
 Share

Recommended Posts

I'm having trouble reading my joystick button press'. I can get the 6-axis and POV but the buttons are always returning 0 for me...

#cs
vi:ts=4 sw=4:
typedef struct joyinfoex_tag { 
    DWORD dwSize; 
    DWORD dwFlags; 
    DWORD dwXpos; 
    DWORD dwYpos; 
    DWORD dwZpos; 
    DWORD dwRpos; 
    DWORD dwUpos; 
    DWORD dwVpos; 
    DWORD dwButtons; 
    DWORD dwButtonNumber; 
    DWORD dwPOV; 
    DWORD dwReserved1; 
    DWORD dwReserved2; 
} JOYINFOEX; 
#ce
Opt("MustDeclareVars",1)
#include <DllMem.au3>
#include <GUIConstants.au3>

Local $JOYINFOEX_struct = "dword(13)"
Local $joy,$coor,$h,$s,$msg

$joy    = _JoyInit()

GUICreate("Joystick Test",300,300)
$h= GuiCtrlCreatelabel("",10,10,290,290)
GUISetState()

while 1
    $msg    = GUIGetMSG()
    $coor   = _GetJoy($joy,0)
    $s      = "Joystick(0):" & @CRLF & _
                "X: " & $coor[0] & @CRLF & _
                "Y: " & $coor[1] & @CRLF & _
                "Z: " & $coor[2] & @CRLF & _
                "R: " & $coor[3] & @CRLF & _
                "U: " & $coor[4] & @CRLF & _
                "V: " & $coor[5] & @CRLF & _
                "POV: " & $coor[6] & @CRLF & _
                "Buttons: " & $coor[7]
    GUICtrlSetData($h,$s,1)
    sleep(10)
    if $msg = $GUI_EVENT_CLOSE Then Exitloop
WEnd


;======================================
;   _JoyInit()
;======================================
Func _JoyInit()
    Local $joy

    $joy    = _DllMemCreate($JOYINFOEX_struct)
    if Not $joy Then Return 0
    _DllMemSet($joy,$JOYINFOEX_struct,0,_DllMemStructSize($JOYINFOEX_struct),0)
    _DllMemSet($joy,$JOYINFOEX_struct,0,255,1)
    return $joy
EndFunc

;======================================
;   _GetJoy($lpJoy,$iJoy)
;   $lpJoy  Return from _JoyInit()
;   $iJoy   Joystick # 0-15
;   Return  Array containing X-Pos, Y-Pos, Z-Pos, R-Pos, U-Pos, V-Pos,POV
;           Buttons down
;
;           *POV This is a digital game pad, not analog joystick
;           65535   = Not pressed
;           0       = U
;           4500    = UR
;           9000    = R
;           Goes around clockwise increasing 4500 for each position
;======================================
Func _GetJoy($lpJoy,$iJoy)
    Local $coor,$ret

    Dim $coor[8]
    $ret = DllCall("Winmm.dll","int","joyGetPosEx",_
                    "int",$iJoy,_
                    "ptr",$lpJoy)
    if Not @error Then
        $coor[0]    = _DllMemGet($lpJoy,$JOYINFOEX_struct,0,2)
        $coor[1]    = _DllMemGet($lpJoy,$JOYINFOEX_struct,0,3)
        $coor[2]    = _DllMemGet($lpJoy,$JOYINFOEX_struct,0,4)
        $coor[3]    = _DllMemGet($lpJoy,$JOYINFOEX_struct,0,5)
        $coor[4]    = _DllMemGet($lpJoy,$JOYINFOEX_struct,0,6)
        $coor[5]    = _DllMemGet($lpJoy,$JOYINFOEX_struct,0,7)
        $coor[6]    = _DllMemGet($lpJoy,$JOYINFOEX_struct,0,10)
        $coor[7]    = _DllMemGet($lpJoy,$JOYINFOEX_struct,0,8)
    EndIf

    return $coor
EndFunc

JoyStick2.zip

Edited by Ejoc
Start -> Programs -> AutoIt v3 -> AutoIt Help File -> Index -> (The Function you are asking about)----- Links -----DllStruct UDFsRSA Crypto UDFs
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...