Jump to content

Reading joystick inputs?


Recommended Posts

Search the forim for "joystick" and you will find some threads discussing this subject.

Here is an that might do what you need.

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Here's an example

;================================================================
; Identificação dos joystick's 0=joy2, 1=joy2, 2=joy3, 3=joy4...
;================================================================
local $JOYID1 = 2; ID do joystick 1
local $JOYID2 = 3; ID do joystick 2
Local $JOYNOERROR = 0 , $JOY_CENTRO = 35999
local $b1, $b10, $b11, $b12, $b2, $b3, $b4, $b5, $b6, $b7, $b8, $b9
local $bb1, $bb10, $bb11, $bb12, $bb2, $bb3, $bb4, $bb5, $bb6, $bb7, $bb8, $bb9
local $driver
local $JOYINFO1, $JOYINFO2, $lbl1, $logo, $msg
local $s1, $s2, $s3, $s4, $ss1, $ss2, $ss3, $ss4, $x1, $x2, $y1, $y2
local $bt_joy1, $bt_joy2
local $retjoy1, $retjoy2, $str, $brgui, $logo, $fon, $font
local $WS_POPUP = 0x80000000
Local $JOYINFO1, $JOYINFO2,$str; informações dos joysticks
; se quiser pegar de um arquivo ini use estas linhas:
;Local $JOYID1 = IniRead(".Joysticks.ini","identificação","Joystick_1",""); identifica o joystick 1
;Local $JOYID2 = IniRead(".Joysticks.ini","identificação","Joystick_2","") ; identifica o joystick 2
$str = "int x;int y;int z;int buttons"
$JOYINFO1 = DllStructCreate($str)
$JOYINFO2 = DllStructCreate($str)
While 1
$retjoy1=DllCall("winmm.dll", "int", "joyGetPos", "int", $JOYID1, "ptr", DllStructGetPtr($JOYINFO1))
$retjoy2=DllCall("winmm.dll", "int", "joyGetPos", "int", $JOYID2, "ptr", DllStructGetPtr($JOYINFO2))
;pega os valores preenchidos pela função JoyGetPos
$bt_joy1=DllStructGetData($JOYINFO1,"buttons")
$bt_joy2=DllStructGetData($JOYINFO2,"buttons")
$x1=DllStructGetData($JOYINFO1,"x")
$x2=DllStructGetData($JOYINFO2,"x")
$y1=DllStructGetData($JOYINFO1,"y")
$y2=DllStructGetData($JOYINFO2,"y")
If BitAND($bt_joy1,1) Then send("B1 Player 1 ");botão 1
If BitAND($bt_joy1,2) Then send("B2 Player 1 ");botão 2
If BitAND($bt_joy1,4) Then send("B3 Player 1 ");botão 3
If BitAND($bt_joy1,8) Then send("B4 Player 1 ");botão 4
If BitAND($bt_joy1,16) Then send("B5 Player 1 ");botão 5
If BitAND($bt_joy1,32) Then send("B6 Player 1 ");botão 6
If BitAND($bt_joy1,64) Then send("B7 Player 1 ");botão 7
If BitAND($bt_joy1,128) Then send("B8 Player 1 ");botão 8
If BitAND($bt_joy1,256) Then send("B9 Player 1 ");botão 9
If $y1 = 0 Then send("Cima Player 1 "); cima player 1
if $y1 > 35999 Then send("Baixo Player 1 "); 32767 = joystick físico e 35999 = joystick virtual
If $x1 = 0 Then send("esquerda Player 1 "); esquerda player 1
if $x1 > 35999 Then send("direita Player 1 "); 32767 = joystick físico e 35999 = joystick virtual
If BitAND($bt_joy2,1) Then send("B1 Player 2 ");botão 1
If BitAND($bt_joy2,2) Then send("B2 Player 2 ");botão 2
If BitAND($bt_joy2,4) Then send("B3 Player 2 ");botão 3
If BitAND($bt_joy2,8) Then send("B4 Player 2 ");botão 4
If BitAND($bt_joy2,16) Then send("B5 Player 2 ");botão 5
If BitAND($bt_joy2,32) Then send("B6 Player 2 ");botão 6
If BitAND($bt_joy2,64) Then send("B7 Player 2 ");botão 7
If BitAND($bt_joy2,128) Then send("B8 Player 2 ");botão 8
If BitAND($bt_joy2,256) Then send("B9 Player 2 ");botão 9
If $y2 = 0 Then send("Cima Player 2 "); cima player 1
if $y2 > 35999 Then send("Baixo Player 2 "); 32767 = joystick físico e 35999 = joystick virtual
If $x2 = 0 Then send("esquerda Player 2 "); esquerda player 1
if $x2 > 35999 Then send("direita Player 2 "); 32767 = joystick físico e 35999 = joystick virtual
Sleep(50); dá um intervalo de 50 milisegundos
Wend
$JOYINFO1 =0;libera a memoria alocada pela estrutura do joystick 1
$JOYINFO2 =0 ;libera a memoria alocada pela estrutura do joystick 2
Exit(0); encerra o script

Open the pocket of notes and press the

Link to comment
Share on other sites

Belini: That script doesn't seem to be compatible with my stick. It just keeps Cima Player 1 and Cima Player 2 repeatedly.

Water: The UDF you linked me to (the modified one in that thread) seems to detect my stick and button presses, but I'm guessing there's no way to pass the ID of a button to HotKeySet? Should I just poll for a button press in a loop?

Link to comment
Share on other sites

Unfortunately I haven't used this UDF myself. I just searched the forum - that's it ;)

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

But I have used it and its awesome. I configured the modified script mentioned to work on a Gamepad. Now, when I press button 1, it displays an empty msgbox. Here is my version:

Local $joy,$coor,$h,$s,$msg
$joy    = _JoyInit()

;_____________________________________________________________________
while 1
    $coord=_GetJoy($joy,0)
    Switch $coord[7]
    Case 1
    msgbox(64, "", "You pressed button 1")
    EndSwitch
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)
        $coor[1]    = DllStructGetData($lpJoy,1,4)
        $coor[2]    = DllStructGetData($lpJoy,1,5)
        $coor[3]    = DllStructGetData($lpJoy,1,6)
        $coor[4]    = DllStructGetData($lpJoy,1,7)
        $coor[5]    = DllStructGetData($lpJoy,1,8)
        $coor[6]    = DllStructGetData($lpJoy,1,11)
        $coor[7]    = DllStructGetData($lpJoy,1,9)
    EndIf
    return $coor
EndFunc

As far as HotKeySet is concerned, I am afraid you can't pass ButtonID to it. Perhaps, this is the best way so far. Use a combination of $coord[1], $coord[2], $coord[3] for your purpose.

Edited by MKISH

----------------------------------------

:bye: Hey there, was I helpful?

----------------------------------------

My Current OS: Win8 PRO (64-bit); Current AutoIt Version: v3.3.8.1

Link to comment
Share on other sites

SE $ y2> 35999 ; ==> 35999 = joystick virtual

SE $ x2> 35999 ; ==> 35999 = joystick virtual

change to:

SE $ y2> 32767 ; ==> 32767 = phisical joystick

SE $ x2> 32767 ; ==> 32767 = physical joystick

Edited by Belini
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...