Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;____________________________________________________________________
- ; Original program by Ejoc ;
- ; Improved by Adam1213 (autoit 3.2 compatiblity + improved labels ;
- ;____________________________________________________________________
- #Include <GUIConstants.au3>
- ;_________________ SETUP_____________________________________
- Local $joy,$coor,$h,$s,$msg
- $joy = _JoyInit()
- Dim $labels_text[8]=['X', 'Y', 'Z', 'R', 'U', 'V', 'POV', 'Buttons']
- Dim $labels_no=UBound($labels_text)
- Dim $labels[$labels_no]
- Dim $labels_value[$labels_no]
- ;__________ CONFIG ____________________________________________
- ;---------- Find the max length of the longest label --------------
- $label_len=0
- For $text In $labels_text
- $len=StringLen($text)
- If $len>$label_len Then
- $label_len=$len
- EndIf
- Next
- $label_len*=6
- ;_____________ GUI _______________________________________________
- GUICreate('Joystick Test', 200, 200)
- GUICtrlCreateLabel('Joystick', 40, 20, 100, 20)
- For $i=0 To $labels_no-1
- GUICtrlCreateLabel($labels_text[$i]&':', 10, 60+$i*12, $label_len, 12)
- $labels[$i]=GUICtrlCreateLabel('', 10+$label_len, 60+$i*12, 70, 12)
- $labels_value[$i]=''
- Next
- GUISetState()
- ;_____________________________________________________________________
- While 1
- $coord=_GetJoy($joy,0)
- For $i=0 To UBound($coord)-1
- If $coord[$i]<>$labels_value[$i] Then
- GUICtrlSetData($labels[$i], $coord[$i])
- $labels_value[$i]=$coord[$i]
- EndIf
- Next
- Sleep(10)
- $msg =GUIGetMsg()
- If $msg = $GUI_EVENT_CLOSE Then ExitLoop
- WEnd
- $lpJoy=0 ; Joyclose
- ;======================================
- ; _JoyInit()
- ;======================================
- Func _JoyInit()
- Local $joy
- Global $JOYINFOEX_struct = "dword[13]"
- $joy=DllStructCreate($JOYINFOEX_struct)
- If @Error Then Return 0
- DllStructSetData($joy, 1, DllStructGetSize($joy), 1);dwSize = sizeof(struct)
- DllStructSetData($joy, 1, 255, 2) ;dwFlags = GetAll
- 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]
- DllCall("Winmm.dll","int","joyGetPosEx", _
- "int",$iJoy, _
- "ptr",DllStructGetPtr($lpJoy))
- If NOT @Error Then
- $coor[0] = DllStructGetData($lpJoy,1,3) ; X Axis
- $coor[1] = DllStructGetData($lpJoy,1,4) ; Y Axis
- $coor[2] = DllStructGetData($lpJoy,1,5) ; Z Axis
- $coor[3] = DllStructGetData($lpJoy,1,6) ; R Axis
- $coor[4] = DllStructGetData($lpJoy,1,7) ; U Axis
- $coor[5] = DllStructGetData($lpJoy,1,8) ; V Axis
- $coor[6] = DllStructGetData($lpJoy,1,11); POV Value
- $coor[7] = DllStructGetData($lpJoy,1,9) ; Buttons Mask
- EndIf
- Return $coor
- EndFunc
Add Comment
Please, Sign In to add comment