How to simulate a joystick or gamepad -button press?

Multi tool use
Multi tool use


How to simulate a joystick or gamepad -button press?



How to simulate a joystick or gamepad -button press using an AutoIt script? E.g. pressing button A on an Xbox360 controller.




1 Answer
1



Try this :


#include <GUIConstants.au3>

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

_JoyClose($joy)

;======================================
; _JoyInit()
;======================================
Func _JoyInit()
Local $joy
Global $JOYINFOEX_struct = "dword[13]"

$joy = DllStructCreate($JOYINFOEX_struct)
If @error Then Return 0
DllStructSet($joy, 1, DllStructSize($joy), 1);dwSize = sizeof(struct)
DllStructSet($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", DllStructPtr($lpJoy) _
)

If Not @error Then
$coor[0] = DllStructGet($lpJoy, 1, 3)
$coor[1] = DllStructGet($lpJoy, 1, 4)
$coor[2] = DllStructGet($lpJoy, 1, 5)
$coor[3] = DllStructGet($lpJoy, 1, 6)
$coor[4] = DllStructGet($lpJoy, 1, 7)
$coor[5] = DllStructGet($lpJoy, 1, 8)
$coor[6] = DllStructGet($lpJoy, 1, 11)
$coor[7] = DllStructGet($lpJoy, 1, 9)
EndIf

Return $coor
EndFunc

;======================================
; _JoyClose($lpJoy)
; Free the memory allocated for the joystick struct
;======================================
Func _JoyClose($lpJoy)
DllStructFree($lpJoy)
EndFunc



More info here.





Hi, I tried this before asking this question, this is only show the buttons pressed
– JatSing
Oct 19 '13 at 10:15





@JatSing I believe every button on a keypad has its button on a keyboard. You can use ControlSend() or Send() to achieve this.
– Milos
Oct 20 '13 at 10:12






No, my case is special.
– JatSing
Oct 20 '13 at 21:12






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

qy 3SH7S8AHJYOWdhrR3up qu807zBkDVCCp7y,a
lAps jw5j,h71p 3vN754QVIk,MPAXOJ iJTY6ypGUlOu 224H7oR 6 qPmZMteXdhvwvzrA5Y2R8,zmAEFsl,BNod,MPoKqcFRhvIyKaUc

Popular posts from this blog

Delphi Android file open failure with API 26

.

Amasya