Jump to content
mutleey

Looping by pressing the joystick button

Recommended Posts

mutleey

Hello guys, I have a problem here and needed your help.

I need this script to be looping when pressed a button joystick, and then loose the button to perform a function

in the case when pressed any button on the joystick enter the loop and when you release the button to appear the message.

thank you.

#Include <GUIConstants.au3>

Local $Joystick, $coor, $h, $s, $msg
Local $num = 0

$Joystick = _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]

; 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($Joystick, 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]
;-----------------------------------------------------
            While $coord[7]
                Sleep(10)
            WEnd
            MsgBox(0, "Joy", "loose button", 1)
;----------------------------------------------------
        EndIf
   Next
    Sleep(10)
    $msg =GUIGetMsg()
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
WEnd

$lpJoy=0 ; Joyclose

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

    $Joystick=DllStructCreate($JOYINFOEX_struct)
    If @Error Then Return 0
    DllStructSetData($Joystick, 1, DllStructGetSize($Joystick), 1);dwSize = sizeof(struct)
    DllStructSetData($Joystick, 1, 255, 2)            ;dwFlags = GetAll
    Return $Joystick
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

Edit:

contrary to what you might think is not automation games, but a mechanical arm controlled by a joystick (analog) only by pressing the function assigned to it is called several times, even giving a touch very quickly on the button.

I do not know if it violates the rules of the forum, anyway thanks.

Edited by mutleey

Share this post


Link to post
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

  • Similar Content

    • nacerbaaziz
      By nacerbaaziz

      Hi dear
      This is the first include file I designed
      This work is especially directed to NVDA free screen reader users
      It contains a set of functions that enable you to control the program
      Such as forcing the program to read a custom text
      Force it to stop talking
      Find out if the program is running
      And show custom text in the Braille screen
      Available functions are
      _nvdaControllerClient_Load()
      to load the dll file
      _nvdaControllerClient_free()
      to UnLoad the dll file
      _nvdaControllerClient_SpeakText()
      to speak a custom text
      _nvdaControllerClient_brailleMessage()
      to show custom text in the Braille screen
      _nvdaControllerClient_cancelSpeech()
      to Force the NVDA  to stop talking
      _nvdaControllerClient_testIfRunning()
      to check if the NVDA is running
      important note :
      All of these functions depend on a nvdaControllerClient32.dll
      I've added it in the attachments, as well as a file for examples, and other files
      As the source and examples in other languages
      For those who wanted to download the free screen reader, this is the download link from the official website
      https://www.nvaccess.org/download/
      i hope you like this topic
      I hope you will try it and give me your opinions
      Thank you all members and administrators for their help
      now with the  Attachments
       
      nvdaControllerClient_UDF.zip
    • RHolmes
      By RHolmes
      I wrote a script a few months ago that was working at the time. When I tried it today it wouldn't retrieve any controls.  The application successfully launches, but I cannot figure out how to retrieve the control from the window that is launched. I'm on a windows 10 machine using AutoIt v3.3.14.2. The only thing I can think of that has changed is windows updates? Code is below, any help is greatly appreciated.    ; Notes: ; HandleError( handleToCheck, MsgToLogOnFailure, terminateAutoItOnFail ) : function that simply checks the handle and quits AutoIt if not present ; all of this works well FileChangeDir( $CLIENT_APPLICATION_DIR ); Run( "Client.exe" ) Local $hClient = WinWaitActive( $CLIENT_TITLE, "", 10 ) $terminateOnFail = 1 HandleError( $hClient, "LaunchClient::Error: Failed to launch client. Either timed-out or failed.", $terminateOnFail ) LogToFile( "Client launched, waiting for system to ready." ) Sleep( 5000 ) ; this part does not work ; $SYSTEM_INDICATOR is a global variable. I have tried these values: "SystemIndicatorWindow" (Text), "Qt5QWindowIcon101" (ClassNN), and ; "[CLASS:Qt5QWindowIcon; INSTANCE:101]" Local $hStatusIndicator = ControlGetHandle( $hClient, "", $SYSTEM_INDICATOR ) HandleError( $hStatusIndicator, "CheckStatus::Error: couldn't retrieve control: " & $SYSTEM_INDICATOR, $terminateOnFail ) This is what the spy reveals: 

       
      Edit: I just tried this code and it works for notepad++.
      FileChangeDir( "C:\Program Files\Notepad++\" ); Run( "notepad++.exe" ) Local $hNotePad = WinWaitActive( "new 1 - Notepad++", "", 10 ) If $hNotePad = 0 Or $hNotePad = -1 Then MsgBox( $MB_SYSTEMMODAL, "Error", "Error getting app handle." ) EndIf Sleep( 1000 ) Local $hNewFileBtn = ControlGetHandle( $hNotePad, "", "[CLASS:ToolbarWindow32; INSTANCE:1]" ) If $hNewFileBtn = 0 Or $hNewFileBtn = -1 Then MsgBox( $MB_SYSTEMMODAL, "Error", "Error getting button handle." ) EndIf MsgBox( $MB_SYSTEMMODAL, "Success", "Success." )  
    • rcmaehl
      By rcmaehl
      A UDF with Extended Functions for Window Management
       
      Notes:
      Fixes WinGetClassList's barbaric returning of a @LF separated string instead of an array.
       
      Potential Uses:
      Automating applications that change their controls' handles/classes on each launch (e.g. half of Cisco's programs)
       
      Functions:
      _WinGetClassList
      _WinGetClassNNList
      _WindowGetHandleList
      _WindowGetHandleListFromPos
       
      Download: 
      WindowEx.zip  (v0.4)
       
      Changelog:
      10/04/2016 (v0.4): _WinGetClassNNList Fixed : Not Returning an Index when using $2D_ARRAY _WinGetClassNNList Fixed : Not Properly returning $aArray[x][1] on Classes with instances > 9 when using $2D_ARRAY 10/03/2016 (v0.3): _WinGetClassList Added : Exactly the same as WinGetClassList but returns a more civilized Array _WinGetClassNNList Added : Returns Classes and their instances in either a 1D or 2D array depending on Flags _WindowGetHandleList Renamed: _WinGetHandleList SCRIPT BREAKING! _WindowGetHandleListFromPos Renamed: _WinGetHandleListFromPos SCRIPT BREAKING! 10/01/2016 (v0.2): WindowsExConstants.au3 Added : Flags in _WindowGetHandleListFromPos _WindowGetHandleListFromPos Removed: ConsoleWrite left in during debug _WindowGetHandleListFromPos Added : Flag for if part of a Control is at $X, $Y return it as well. 10/01/2016 (v0.1): _WindowGetHandleList Added : Retrieves the handles of classes from a window. _WindowGetHandleListFromPos Added : Retrieves the handles of classes at a specific position from a window. Known and Reported Bugs:
      None reported To Do:
      To Be Decided. Opinions welcome! Upcoming Changes:
      To Be Decided.
    • kcvinu
      By kcvinu
      Hi all,
      I am playing with _GUICtrlButton_Create function. How can i change this button's (or the entire form's) font ?. The in-built GUICtrlSetFont function is not working even when i convert the control handle to control ID with _WinAPI_GetDlgCtrlID ( ) function.  Do i need to use CreateFont api finction and send WM_SETFONT message ? Or is there any other easy and safe ways to do this ?. Thanks in advance.
      Note : This window is created by CreateWindowEx function, not by GUICreate function. 
    • AnonymousX
      By AnonymousX
      Hello,
      I'm trying to make a program that can look at a folder directory, find all the CSV files, and then add the data from CSV's to an array. 
      The problem I seem to be running into is on the 2nd iteration (2nd file) when the script will not create an array. Could someone please help? Thanks in advance
       
      #include <Array.au3> #include <File.au3> #include <MsgBoxConstants.au3> #include <Excel.au3> #include <MsgBoxConstants.au3> Global $MasterArray RefineData() Func RefineData() Local $i, $filenum, $file, $csvArray, $sFilePath = @ScriptDir $fileList = _FileListToArrayRec($sFilePath, "*.csv", 1) ;Create and array of all .csv files within folder ;=====Loop through the .csv files within the folder====== For $filenum = 1 To UBound($fileList) - 1 Step 1 $file = $fileList[$filenum] $sFilePath = $sFilePath & "\" & $file ;=====Create array based on csv file===== _FileReadToArray($sFilePath, $csvArray, $FRTA_NOCOUNT, ",") _ArrayDisplay($csvArray,"File: " & $filenum) If $filenum = 1 Then $MasterArray = $csvArray _ArrayDisplay($MasterArray, "Master") Else $MasterArray = _ArrayColInsert($MasterArray, UBound($MasterArray)) ;want column added at end For $i = 0 To UBound($MasterArray)-1 Step 1 $MasterArray[$i][UBound($MasterArray) - 1] = $csvArray[$i][4] Next _ArrayDisplay($MasterArray, "Master") EndIf Next EndFunc ;==>RefineData  
×