Guest User

Untitled

a guest
Apr 17th, 2018
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
AutoIt 3.28 KB | None | 0 0
  1. ;____________________________________________________________________
  2. ;      Original program by Ejoc                           ;
  3. ;      Improved by Adam1213 (autoit 3.2 compatiblity + improved labels            ;
  4. ;____________________________________________________________________
  5.  
  6. #Include <GUIConstants.au3>
  7.  
  8. ;_________________ SETUP_____________________________________
  9. Local $joy,$coor,$h,$s,$msg
  10.  
  11. $joy    = _JoyInit()
  12.  
  13. Dim $labels_text[8]=['X', 'Y', 'Z', 'R', 'U', 'V', 'POV', 'Buttons']
  14. Dim $labels_no=UBound($labels_text)
  15. Dim $labels[$labels_no]
  16. Dim $labels_value[$labels_no]
  17. ;__________ CONFIG ____________________________________________
  18. ;---------- Find the max length of the longest label --------------
  19. $label_len=0
  20. For $text In $labels_text
  21.     $len=StringLen($text)
  22.     If $len>$label_len Then
  23.         $label_len=$len
  24.     EndIf
  25. Next
  26. $label_len*=6
  27. ;_____________ GUI _______________________________________________
  28. GUICreate('Joystick Test', 200, 200)
  29. GUICtrlCreateLabel('Joystick', 40, 20, 100, 20)
  30.  
  31. For $i=0 To $labels_no-1
  32.     GUICtrlCreateLabel($labels_text[$i]&':', 10, 60+$i*12, $label_len, 12)
  33.     $labels[$i]=GUICtrlCreateLabel('', 10+$label_len, 60+$i*12, 70, 12)
  34.     $labels_value[$i]=''
  35. Next
  36. GUISetState()
  37. ;_____________________________________________________________________
  38.  
  39. While 1
  40.     $coord=_GetJoy($joy,0)
  41.     For $i=0 To UBound($coord)-1
  42.         If $coord[$i]<>$labels_value[$i] Then
  43.             GUICtrlSetData($labels[$i], $coord[$i])
  44.             $labels_value[$i]=$coord[$i]
  45.         EndIf
  46.    Next
  47.     Sleep(10)
  48.     $msg =GUIGetMsg()
  49.     If $msg = $GUI_EVENT_CLOSE Then ExitLoop
  50. WEnd
  51.  
  52. $lpJoy=0 ; Joyclose
  53.  
  54. ;======================================
  55. ;   _JoyInit()
  56. ;======================================
  57. Func _JoyInit()
  58.     Local $joy
  59.     Global $JOYINFOEX_struct    = "dword[13]"
  60.  
  61.     $joy=DllStructCreate($JOYINFOEX_struct)
  62.     If @Error Then Return 0
  63.     DllStructSetData($joy, 1, DllStructGetSize($joy), 1);dwSize = sizeof(struct)
  64.     DllStructSetData($joy, 1, 255, 2)            ;dwFlags = GetAll
  65.     Return $joy
  66. EndFunc
  67.  
  68. ;======================================
  69. ;   _GetJoy($lpJoy,$iJoy)
  70. ;   $lpJoy Return from _JoyInit()
  71. ;   $iJoy  Joystick # 0-15
  72. ;   Return Array containing X-Pos, Y-Pos, Z-Pos, R-Pos, U-Pos, V-Pos,POV
  73. ;         Buttons down
  74. ;
  75. ;         *POV This is a digital game pad, not analog joystick
  76. ;         65535  = Not pressed
  77. ;         0    = U
  78. ;         4500   = UR
  79. ;         9000   = R
  80. ;         Goes around clockwise increasing 4500 for each position
  81. ;======================================
  82. Func _GetJoy($lpJoy,$iJoy)
  83.     Local $coor,$ret
  84.  
  85.     Dim $coor[8]
  86.     DllCall("Winmm.dll","int","joyGetPosEx", _
  87.             "int",$iJoy, _
  88.             "ptr",DllStructGetPtr($lpJoy))
  89.  
  90.     If NOT @Error Then
  91.         $coor[0] = DllStructGetData($lpJoy,1,3) ; X Axis
  92.         $coor[1] = DllStructGetData($lpJoy,1,4) ; Y Axis
  93.         $coor[2] = DllStructGetData($lpJoy,1,5) ; Z Axis
  94.         $coor[3] = DllStructGetData($lpJoy,1,6) ; R Axis
  95.         $coor[4] = DllStructGetData($lpJoy,1,7) ; U Axis
  96.         $coor[5] = DllStructGetData($lpJoy,1,8) ; V Axis
  97.         $coor[6] = DllStructGetData($lpJoy,1,11); POV Value
  98.         $coor[7] = DllStructGetData($lpJoy,1,9) ; Buttons Mask
  99.     EndIf
  100.  
  101.     Return $coor
  102. EndFunc
Add Comment
Please, Sign In to add comment