Jump to content
mutleey

Looping by pressing the joystick button

Recommended Posts

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

    • By nacerbaaziz
      hello sirs, please i created a tool witch get the focused control in a window and play a audio file linked with this controls
      e.g buttons, checkBoxes, radios, comboboxes, and others
      i know that their is a function that give us the control focus but it return the classNN
      i want to get the class name to use it with a switch and
      because their are more than class e.g button tbutton timagebutton tnewButton...
      please can any one help me to get the class name not the classnn
      thanks in advance
    • By nacerbaaziz
      Hello my friends
      Can we create a single context menu on more than one item?
      For example, a context menu includes standardized options on more than one control, such as buttons or check boxes
      to Create a context menu on one item am using this function
      GUICtrlCreateContextMenu ($ HWND)
      How to link it with more than one element please?
      or if we can't do that, please give me a solution
      so i tried to add an context menus to all the controls but the script will be long, for that if their are any solutions i hope to give it to me
      thanks in advanced
    • By TheAutomator
      Is there a (simple) way to make your script using a picture-control to resize the gui?
      This would be useful for a transparant pop-up window with a custom made theme using picture controls:
      $Form = GUICreate('', 301, 173, 5, 5, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_TOPMOST)) GUICtrlCreatePic(@scriptdir & "\resize_win.bmp", 0, 73, 20, 51) ; some api call or code telling the os to use this picture as a resize border GUICtrlSetResizing(-1, $GUI_DOCKLEFT+$GUI_DOCKTOP+$GUI_DOCKBOTTOM+$GUI_DOCKWIDTH+$GUI_DOCKHEIGHT) GUISetState(@SW_SHOW) While True if GUIGetMsg() = $GUI_EVENT_CLOSE then Exit WEnd  
      EDIT: to make it more clear what i wanna do, if you go with the mouse arrow over the border of a re-sizable window the arrow changes to a "resize" arrow, you click and drag the border and then the window size adjusts to the mouse position until you release the mouse button.
      I want my picture control to be used the same way as the resize border to resize my window.
    • By ur
      An application is there which is created using vc++,mostly mfc.
       
      DOn't know the details completely.
       
      WHen I try to automate the control clicks for testing the UI.
      THe below control is not detected.
      As you can see, during UI operations I can click the elements one by one.
      But all the elements is selected as a whole set, when I use the Windowinfo tool.

       
      How to click this using AutoIT.?
       
      Please suggest.
    • By ergo
      Hello AutoIt-Fans. The main reason why I wrote this script was to simulate the entire keyboard with just the joypad. Mostly I need it when I play retro games on an emulator like CCS64 or VICE emulator, PCSXR, ... So maybe someone can use it too.
      In the configuration file macroJoy.cfg you can define your macros. A macro has two parts, a button sequence-line and the commands-line. If all buttons of a sequence-line (one by one or simultaneously, depending on pushType) are pressed, the functions in the commands-line will be invoked. The following functions are currently available: sendkey, run, focus, killproc, cursor, sleep. If you like you can add some custom functions in includes/functions.au3. Below you will find a configuration example and a brief description.
      The program resides in the system tray. Use the menu item Check JoyData to test your macros or see the joystick button codes. 
       
      Project files can be downloaded from Github macroJoy Source code.zip
      Enjoy!!
      [config] ;sequenceNN: process;pushType;joynum;time;joyid,code;joyid,code,... ;process: 0=ignore process / processID or process name e.g.: notepad.exe ;pushType: 1=simultaneous, 2=one by one ;JoyPort: 1-15 ;time(pushType 1): [idle-repeat time in ms] or 0=off / (pushType 2): [timeout in ms] or 0=no timeout ;joyid: 1-8 ;code: integer value ;commandNN: func,para1,para2,...;func,para1,para2,... ;functions ;sleep pause execution para1: time in ms ;sendKey simulate keystrokes para1: sequence of keys / para2(opt): 0=default 1=send raw (see autoit docs "send" for details) ;focusA focus to the specified window name para1: window name ;killpidfile kill process from pid-file para1: text file with a process id ;focusB focus to the specified window name para1: window name (Works better, but may be unavailable in subsequent versions of Windows.) ;killproc kill process by name or process id para1: process name or process id ;run run a program para1: program name / para2(opt): show_flag / para3(opt): opt_flag (see autoit docs "run" for details) ;cursor hide/set or toggle mouse cursor para1: 0=hide 1=show 2=toggle sequence01=0;2;1;2000;8,128;8,0;8,64 command01=sendKey,!{F4},0;sleep,1000;sleep,5000;focusA,Kodi sequence02=0;2;2;3000;8,128;8,0;8,128;8,0;8,64;8,0;8,64 command02=sendKey,{F2},0 ;XINPUT: <Start> sequence03=ccs64.exe;1;1;0;8,128 command03=sendKey,{ESC down},0;sleep,100;sendKey,{ESC up},0 ;XINPUT: <Square> sequence04=ccs64.exe;1;1;0;8,4 command04=sendKey,{z down},0;sleep,100;sendKey,{z up},0 ;XINPUT: <R1>+<D-Up> sequence05=ccs64.exe;1;1;0;8,32;7,0 command05=sendKey,{F1 down},0;sleep,300;sendKey,{F1 up},0 ;XINPUT: <R1>+<D-Right> sequence06=ccs64.exe;1;1;0;8,32;7,9000 command06=sendKey,{F3 down},0;sleep,300;sendKey,{F3 up},0 ;XINPUT: <L3> Toggle Mouse Cursor On/Off sequence07=0;1;1;0;8,256 command07=cursor,2 ;XINPUT: <R3> Run Notepad and open desktop.ini, killproc after 3 seconds sequence08=0;1;1;0;8,512 command08=run,notepad.exe "%USERPROFILE%\Desktop\desktop.ini",c:\;sleep,3000;killproc,notepad.exe  

×
×
  • Create New...