Jump to content

Control your programs by joystick or joypad

Recommended Posts

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



;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,...
        ;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



;XINPUT: <Start>
command03=sendKey,{ESC down},0;sleep,100;sendKey,{ESC up},0

;XINPUT: <Square>
command04=sendKey,{z down},0;sleep,100;sendKey,{z up},0

;XINPUT: <R1>+<D-Up>
command05=sendKey,{F1 down},0;sleep,300;sendKey,{F1 up},0

;XINPUT: <R1>+<D-Right>
command06=sendKey,{F3 down},0;sleep,300;sendKey,{F3 up},0

;XINPUT: <L3> Toggle Mouse Cursor On/Off

;XINPUT: <R3> Run Notepad and open desktop.ini, killproc after 3 seconds
command08=run,notepad.exe "%USERPROFILE%\Desktop\desktop.ini",c:\;sleep,3000;killproc,notepad.exe



Edited by ergo
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
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By 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.
    • By Xandy
      I always knew I'd have to write a configure joystick routine to record and return desired user input to be used for player controls.
      This example UDF is mainly to help people just getting started, who have never written a configure joystick routine.
       but it's also a dialog that will setup and load custom controls for as many players as you like.  Just try -12 players for example.
      Example using Configure Controls to setup controls for Tanks that ride on the desktop.
      Damn I broke the jump shadow before the video, ha. I fixed it before the source upload.
      Having seen plenty of configure joystick functions from a user stand point, I had some criteria.
      1. All players controls should be accessible from a single call to the configure function.  Navigating back a dialog just to assign the next player is bullshit.
      2. Can handle analog and digital controls, and not become broken b/c the joystick is special.  Testing please let me know!
      3. GUI but only Nes joystick GUI at this point.

      1. I should be able to detect when the GUIHotkey changes and focus the next field. A joystick does this already.
      2. After seeing better written UDFs I am still considering better variable names.
      3. When you can assign all types of input devices to a single player controls, you allow for multiplayer single player.  B/c of the re-write using both GUIHotkey controls and input fields, I have decided to wait and add this feature latter.  The data is setup to handle it, but the configurecontrols dialog creates all the fields based on the first control type.  Meaning at this point only one input type per player.
      Note: These scripts require an SDL folder environment!
      See download at end of post.
      Configure Controls UDF.au3

      #include-once ; #INDEX# ======================================================================================================================= ; Title .........: Configure Controls ; AutoIt Version : works older versions of AutoIt, unsure how far back ; Description ...: Methods to record user input to a customizable control array ; Author(s) .....: Xandy ; Dll ...........: SDL.dll, SDL_Image.dll ; Functions......: ; _configurecontrols($hgui, $screen, $players, $aControlLabelNames= Default) - - - returns $a_control[$controlmax][$g_cc_controldatamax] ; _cc_savecontrols($control, $filename, $controlinput) ; _cc_loadcontrols($filename, $controlmax, $g_cc_controldatamax) ; _cc_updatecontrolinput($control, byref $controlinput) ; _cc_nesgui_selectiondefine(byref $nespadbuttonselectsurf, byref $nespadrect) ; _cc_surfget($surf, byref $width, byref $height) - - - get the width and height of a SDL_Surface ; _cc_controlchanged($control, $player, $g_cc_controldatamax, $controlinput) ; _cc_openjoystick(byref $joystick, $joystickid, byref $joystickbuttons, byref $joystickaxes, byref $joystickhats) ; _cc_mouseoverrect($mousex, $mousey, $rect, $rect_y= default, $rect_w= default, $rect_h= default) ; _cc_deletecontrolinput(byref $controlinput, byref $control) ; _cc_createcontrolinput(byref $controlinput, $control, $hgui, $guirect) ; _cc_getkeycode($keycode) ; _cc_clearcontrols(byref $control) ; =============================================================================================================================== ; AutoIt source script file #include <Misc.au3> #include <WindowsConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <GuiComboBoxEx.au3> #include "Include Lib\SDL v14\SDL.au3";created by AdmiralAlkex #include "Include Lib\SDL v14\SDL_Image.au3";created by AdmiralAlkex #include "Include Lib\GUIHotkey\GUIHotkey.au3";created by Mat global $g_cc_controlsavepath= @scriptdir&"\Player Config\" global $g_cc_controlsavefilename= "Player_" global $g_cc_controldatamax= 3 global $analog_threshold= 20000 global $buttontypemax= 3 global $buttontype[$buttontypemax][2];min[type][0] and max[type][1] range global enum $e_button= 0, $e_axis= 1, $e_hat= 2 $buttontype[$e_button][0]= 10 $buttontype[$e_button][1]= 10 $buttontype[$e_axis][0]= 20 $buttontype[$e_axis][1]= 9999 $buttontype[$e_hat][0]= 10000 $buttontype[$e_hat][1]= 19999 ; #FUNCTION# ;=============================================================================== ; ; Name...........: _configurecontrols ; Description ...: Saves player control files for keyboard or joystick ; Saves one file per player, but only if the data changes without 'cancel' ; Syntax.........: _configurecontrols($hgui, $screen, $players, $controlmax) ; Parameters ....: $hgui - GUI handle, probably should be the one with $screen attached ; $screen - SDL_Video Surface attached to $hgui ; $players - How many possiable player config files to create or modify ; $aControlNames - An array that has the names of player controls. If Default 8 Nespad controls will be used. func _configurecontrols(byref $hgui, byref $screen, $players, $aControlNames= default) local $controlmax= 8 if $aControlNames= default then local $controllabel[$controlmax]= ["Up", "Down", "Left", "Right", "Select", "Start", "B", "A"] else $controlmax= ubound($aControlNames) local $controllabel[$controlmax] for $i= 0 to $controlmax-1 $controllabel[$i]= $aControlNames[$i] next endif local $a_winrect= wingetpos($hgui) local $joysticks= _SDL_NumJoysticks() local $player= 0 local $joystickbuttons= -1, $joystickaxes= -1, $joystickhats= -1 local $disableaxes= 0 local $guirect= _SDL_Rect_Create(0, 40, $a_winrect[2]-1, 129); local $joystick= 0 local $colorblack= 0 local $control= _cc_loadcontrols($g_cc_controlsavepath&$g_cc_controlsavefilename&$player&".txt", $controlmax, $g_cc_controldatamax) local $joystickid= $control[0][0] local $confirm= 0 ;Prepare screen surface _SDL_FillRect($screen, 0, _SDL_MapRGB($screen, 152, 152, 152));whole screen grey $drect= _SDL_Rect_Create(0, $guirect.y+$guirect.h, $a_winrect[2]-200, $a_winrect-$guirect.h);rect to fill with black _SDL_FillRect($screen, $drect, $colorblack);fill black area _SDL_Flip($screen) ;All GUI controls local $controlinput[$controlmax][2] local $filemenu= guictrlcreatemenu("File") local $filesaveconfig= guictrlcreatemenuitem("Save a backup copy", $filemenu) local $fileloadconfig= guictrlcreatemenuitem("Load a backup config", $filemenu) local $fileexit= guictrlcreatemenuitem("Exit", $filemenu) ;populate input controls and labels for $i= 0 to $controlmax-1;create gui button controls for nespad $controlinput[$i][0]= guictrlcreatelabel($controllabel[$i], $a_winrect[2]-200, $guirect.h+1+($i*25), 75, 25);controlinput guictrlsetfont(-1, 12, 1200) next _cc_createcontrolinput($controlinput, $control, $hgui, $guirect) ;Setup Cancel and Ok button $buttoncancel= guictrlcreatebutton("Cancel", $a_winrect[2]-170, $guirect.h+($controlmax*25)+20, 75, 20) guictrlsetfont($buttoncancel, 14, 400) $buttonok= guictrlcreatebutton("Ok", $a_winrect[2]-80, $guirect.h+($controlmax*25)+20, 55, 20) guictrlsetfont($buttonok, 14, 400) ;Player Number: label and combobox $playerlabel= guictrlcreatelabel("Player Number:", 45, 17, 175, 22) guictrlsetfont($playerlabel, 18, 400) $playercombo= guictrlcreatecombo("1", 45, 40, 55, 30) guictrlsetfont($playercombo, 16, 400) for $i= 1 to $players guictrlsetdata($playercombo, $i) next ;Setup Joystick Name: label and combobox $joysticklabel= guictrlcreatelabel(" Joystick Name: ", 45, 80, 175, 22) guictrlsetfont($joysticklabel, 18, 400) $joysticknamecombo= guictrlcreatecombo("Keyboard", 45, 103, 550, 20, $CBS_DROPDOWNLIST) guictrlsetfont($joysticknamecombo, 14, 400) for $i= 0 to $joysticks-1 guictrlsetdata($joysticknamecombo, _SDL_JoystickName($i)&"|") next _guictrlcombobox_setcursel($joysticknamecombo, $control[0][0]) ;Disable Axes checkbox $disableaxescheckbox= guictrlcreatecheckbox("Disable Axes", 245, 80, 95) guictrlsetfont($disableaxescheckbox, 9, 400) ;Setup Max Axes: label and input $axesmaxlabel= guictrlcreatelabel("Max Axes:", 370, 58, 85) guictrlsetfont($axesmaxlabel, 14, 400) guictrlsettip($axesmaxlabel, "Use when a joystick reports axises incorrectly, but still needs some axis") $axesmaxinput= guictrlcreateinput("", 370, 80, 45, 21, $ES_NUMBER) ;Setup Threshold: label and input $analog_thresholdlabel= guictrlcreatelabel("Threshold:", 485, 58, 90) guictrlsetfont($analog_thresholdlabel, 14, 400) $analog_thresholdinput= guictrlcreateinput($analog_threshold, 485, 80, 55, 21, $ES_NUMBER) _cc_updatecontrolinput($control, $controlinput) guisetstate() local $w= 0, $h= 0 local $nespadsurf= _IMG_Load(@scriptdir&"\..\Graphics\Nespad\nes-pad.png") _cc_surfget($nespadsurf, $w, $h) local $nespadrect= _SDL_Rect_Create(10, $guirect.y+$guirect.h+1-10, $w, $h) local $highlightbutton= -1 local $nespadbuttonselectsurf[$controlmax][4];[$control][0]surf, [1]rect, [2]possiable surf, [3]possiable rect local $mousex= 0, $mousey= 0;to detect graphic control under mouse ; Define GUI button selection graphic placement _cc_nesgui_selectiondefine($nespadbuttonselectsurf, $nespadrect);defines area to blit controls to gui local $rx= 0, $ry= 0, $rw= 0, $rh= 0 local $rect_a= 0 local $redraw= 1 local $newbutton= "do nothing" local $oldhighlightbutton= -1 ;local $msg= $joysticknamecombo local $msg= 0 if $joystickid> 0 then;joystick $joystick= _cc_openjoystick($joystick, $joystickid, $joystickbuttons, $joystickaxes, $joystickhats) endif;joystickid> 0 guictrlsetdata($axesmaxinput, $joystickaxes) $drect= _SDL_Rect_Create($nespadrect.x, $nespadrect.y, $nespadrect.w, $nespadrect.h);nes pad rect do if winactive($hgui) then switch $msg case $joysticknamecombo;joystick selection _cc_deletecontrolinput($controlinput, $control) _cc_clearcontrols($control) $joystickid= _guictrlcombobox_getcursel($joysticknamecombo) $control[0][0]= $joystickid $joystick= _cc_openjoystick($joystick, $joystickid, $joystickbuttons, $joystickaxes, $joystickhats) _cc_createcontrolinput($controlinput, $control, $hgui, $guirect) _cc_updatecontrolinput($control, $controlinput) guictrlsetdata($axesmaxinput, $joystickaxes) case $playercombo if _cc_controlchanged($control, $player, $g_cc_controldatamax, $controlinput) then _cc_savecontrols($control, $g_cc_controlsavepath&$g_cc_controlsavefilename&$player&".txt", $controlinput) _cc_deletecontrolinput($controlinput, $control) $player= _guictrlcombobox_getcursel($playercombo) $control= _cc_loadcontrols($g_cc_controlsavepath&$g_cc_controlsavefilename&$player&".txt", $controlmax, $g_cc_controldatamax) _guictrlcombobox_setcursel($joysticknamecombo, $control[0][0]);use the first control type as combo selection $joystickid= $control[0][0] $joystick= _cc_openjoystick($joystick, $joystickid, $joystickbuttons, $joystickaxes, $joystickhats) _cc_createcontrolinput($controlinput, $control, $hgui, $guirect) _cc_updatecontrolinput($control, $controlinput) guictrlsetdata($axesmaxinput, $joystickaxes) case $disableaxescheckbox $disableaxes= guictrlread($disableaxescheckbox) case $analog_thresholdinput $analog_threshold= int(guictrlread($analog_thresholdinput)) case $buttoncancel exitloop case $fileexit exitloop case $buttonok $confirm= 1 exitloop case $fileloadconfig $loadpath= fileopendialog("Load Control File", $g_cc_controlsavepath, "txt(*.txt)") if @error= 0 then $control= _cc_loadcontrols($loadpath, $controlmax, $g_cc_controldatamax) $joystickid= $control[0][0];use the first control type as combo selection _guictrlcombobox_setcursel($joysticknamecombo, $joystickid) _cc_deletecontrolinput($controlinput, $control) _cc_createcontrolinput($controlinput, $control, $hgui, $guirect) $joystick= _cc_openjoystick($joystick, $joystickid, $joystickbuttons, $joystickaxes, $joystickhats) _cc_updatecontrolinput($control, $controlinput) endif case $filesaveconfig $savepath= filesavedialog("Save Config File", $g_cc_controlsavepath, "txt(*.txt)") if @error= 0 then $temp= stringmid($savepath, stringlen($savepath)-3);test file name extention if $temp<> ".txt" then $savepath= $savepath&".txt";if no .txt ext add one _cc_savecontrols($control, $savepath, $controlinput) endif case $axesmaxinput $joystickaxes= int(guictrlread($axesmaxinput)) endswitch;msg $msg= guigetmsg() ;Enables image click for control selection if _ispressed(1) then;left mouse button down _SDL_GetMouseState($mousex, $mousey) for $i= 0 to 7;$controlmax-1 ; this example only has 8 nespad rects $rect_a= $nespadbuttonselectsurf[$i][1] if _cc_mouseoverrect($mousex, $mousey, $nespadbuttonselectsurf[$i][1].x-9, $nespadbuttonselectsurf[$i][1].y-9, $nespadbuttonselectsurf[$i][1].w+9, $nespadbuttonselectsurf[$i][1].h+9) then $oldhighlightbutton= $highlightbutton $highlightbutton= $i guictrlsetstate($controlinput[$highlightbutton][1], $gui_focus) exitloop endif if $nespadbuttonselectsurf[$i][2]<> 0 then $rect_a= $nespadbuttonselectsurf[$i][3] if _cc_mouseoverrect($mousex, $mousey, $nespadbuttonselectsurf[$i][3]) then $oldhighlightbutton= $highlightbutton $highlightbutton= $i guictrlsetstate($controlinput[$highlightbutton][1], $gui_focus) exitloop endif endif next endif;_ispressed(1) image clicking if $highlightbutton> -1 then;capture user input if int($joystickid)> 0 then;detect joystick _SDL_JoystickUpdate($joystick) ;joystick buttons for $i= 0 to $joystickbuttons;check all the joystick buttons to find button pressed if _SDL_JoystickGetButton($joystick, $i) > 0 then $control[$highlightbutton][0]= $joystickid;keyboard or joystickid $control[$highlightbutton][1]= 10;type: 10button $newbutton= $i $control[$highlightbutton][2]= $newbutton;button or state endif next;button ;joystick axes if $disableaxes<> 1 then;if axes not disabled for $i= 0 to $joystickaxes-1;check the axi $axisintensity= _SDL_JoystickGetAxis($joystick, $i) if $axisintensity < -$analog_threshold then $control[$highlightbutton][1]= $buttontype[$e_axis][0]+$i;type: > 19 to 9999 axis $newbutton= "axis "&$i&" "&$axisintensity $control[$highlightbutton][2]= $axisintensity+1 else if $axisintensity > $analog_threshold then $control[$highlightbutton][1]= $buttontype[$e_axis][0]+$i;type: > 19 to 9999 axis $newbutton= "axis "&$i&" "&$axisintensity $control[$highlightbutton][2]= $axisintensity-1;button or state endif endif next;axis endif;disableaxis ;joystick hats for $i= 0 to $joystickhats $hat= _SDL_JoystickGetHat($joystick, $i) if $hat<> 0 then $control[$highlightbutton][1]= $buttontype[$e_hat][0]+$i $control[$highlightbutton][2]= $hat;button or state $newbutton= "hat "&$i&" "&$hat endif next;hat endif;joystickid> 0 if $newbutton== "do nothing" then ;do nothing else;update the control input fields with user input $control[$highlightbutton][0]= $joystickid;keyboard or joystickid guictrlsetdata($controlinput[$highlightbutton][1], "J"&$joystickid&" "&$newbutton) if $highlightbutton+1> $controlmax-1 then $highlightbutton= -1 guictrlsetstate($buttonok, $gui_focus);last control set, select buttonok else;select next input button to set guictrlsetstate($controlinput[$highlightbutton+1][1], $gui_focus) endif;select next control sleep(400);easy way to prevent spam assignment $newbutton= "do nothing" endif;newbutton else if _ispressed("1B") then exitloop;when no control is highlighted, ESC cancels out of configurejoystick() endif;highlightbutton> -1 if $oldhighlightbutton<> $highlightbutton then $redraw= 1 if $redraw= 1 then $redraw= 0 _SDL_BlitSurface($nespadsurf, 0, $screen, $drect);draw nes pad ;draw button highlight if $highlightbutton> -1 and $highlightbutton< $controlmax then _SDL_BlitSurface($nespadbuttonselectsurf[$highlightbutton][0], 0, $screen, $nespadbuttonselectsurf[$highlightbutton][1]);draw button selected rect1 if $nespadbuttonselectsurf[$highlightbutton][2]<> 0 then _SDL_BlitSurface($nespadbuttonselectsurf[$highlightbutton][2], 0, $screen, $nespadbuttonselectsurf[$highlightbutton][3]);draw button selected rect2 endif endif;highlightbutton control range _SDL_UpdateRect($screen, $nespadrect.x, $nespadrect.y, $nespadrect.w, $nespadrect.h) endif;redraw ;find target button focus if any if $control[0][0]= 0 then $focus_s= controlgetfocus($hgui) for $i= 0 to $controlmax-1 if $focus_s= "msctls_hotkey32"&$i+1 then $oldhighlightbutton= $highlightbutton $highlightbutton= $i exitloop endif next else $focush= ControlGetHandle ($hgui, "", ControlGetFocus($hgui));find the windows control focus $focusid= _WinAPI_GetDlgCtrlID ($focush);find the focus controlid for $i= 0 to $controlmax-1 if $focusid= $controlinput[$i][1] then $oldhighlightbutton= $highlightbutton $highlightbutton= $i endif;a= buttoninput[i][1] next endif endif;winactive(hgui) until $msg= $gui_event_close if $confirm= 1 then _cc_savecontrols($control, $g_cc_controlsavepath&$g_cc_controlsavefilename&$player&".txt", $controlinput) for $i= 0 to $controlmax-1 _SDL_FreeSurface($nespadbuttonselectsurf[$i][0]) next guictrldelete($filemenu) guictrldelete($playerlabel) guictrldelete($playercombo) guictrldelete($joysticknamecombo) guictrldelete($joysticklabel) guictrldelete($disableaxescheckbox) guictrldelete($axesmaxlabel) guictrldelete($axesmaxinput) guictrldelete($analog_thresholdlabel) guictrldelete($analog_thresholdinput) guictrldelete($buttoncancel) guictrldelete($buttonok) for $i= 0 to $controlmax-1 guictrldelete($controlinput[$i][0]);delete label if $control[0][0]= 0 then _GUICtrlHotkey_Delete($controlinput[$i][1]);delete hotkey control else guictrldelete($controlinput[$i][1]);delete gui input control endif next _SDL_FreeSurface($nespadsurf) _SDL_FillRect($screen, 0, $colorblack) _SDL_Flip($screen) sleep(100) return $confirm EndFunc;_configurecontrols($players, $controlmax) ; Save controls to disk func _cc_savecontrols($control, $filename, $controlinput) dircreate($g_cc_controlsavepath) $file= fileopen($filename, 2) if $file<> -1 then for $i= 0 to ubound($control)-1 if $control[0][0]= 0 then $control[$i][0]= 0 $control[$i][1]= 10 $control[$i][2]= _GUICtrlhotkey_GetHotkeyCode($controlinput[$i][1]) endif for $ii= 0 to $g_cc_controldatamax-1 filewriteline($file, $control[$i][$ii]) next next else msgbox(0, "Save Error", "Player controls could NOT be Saved to:"&@CRLF&$filename) endif fileclose($file) EndFunc;_cc_savecontrols($control, $filename, $controlinput) ; Load controls from disk, return control[controlmax][controldatamax] func _cc_loadcontrols($filename, $controlmax, $g_cc_controldatamax) local $control[$controlmax][$g_cc_controldatamax] $file= fileopen($filename) if $file<> -1 then for $i= 0 to $controlmax-1 for $ii= 0 to $g_cc_controldatamax-1 $control[$i][$ii]= int(filereadline($file)) next next fileclose($file) else msgbox(0, "Load Error", "Player controls could NOT be Loaded", 2000) endif;file<> -1 return $control EndFunc;_cc_loadcontrols($filename, $controlmax, $g_cc_controldatamax)() ; updates the control input fields func _cc_updatecontrolinput($control, byref $controlinput) local $newbutton= "" for $i= 0 to ubound($control)-1 if $control[0][0]= 0 then _GUICtrlHotkey_SetHotkeyCode($controlinput[$i][1], $control[$i][2]) else switch $control[$i][1] case $buttontype[$e_button][0] to $buttontype[$e_button][1] $newbutton= $control[$i][2] case $buttontype[$e_axis][0] to $buttontype[$e_axis][1];axis $newbutton= "axis "&$control[$i][1]-20&" "&$control[$i][2] case $buttontype[$e_hat][0] to $buttontype[$e_hat][1];hat $newbutton= "hat "&$control[$i][1]-10000&" "&$control[$i][2] case else;to prevent a J1, J0..controlmax spam on blank controls $newbutton= Null endswitch if $newbutton<> Null then $newbutton= "J"&$control[$i][0]&" "&$newbutton guictrlsetdata($controlinput[$i][1], $newbutton) endif next EndFunc;_cc_updatecontrolinput($control, byref $controlinput) ; Sets the positions and images of selected buttons on the nespad gui func _cc_nesgui_selectiondefine(byref $nespadbuttonselectsurf, byref $nespadrect) local $graphicpath= @scriptdir&"\..\Graphics\Nespad" $nespadbuttonselectsurf[0][0]= _IMG_Load($graphicpath&"\nes-select-up 95 105 28 26.png");up $nespadbuttonselectsurf[0][1]= _SDL_Rect_Create($nespadrect.x+95, $nespadrect.y+105, 28, 26) $nespadbuttonselectsurf[1][0]= _IMG_Load($graphicpath&"\nes-select-down 95 177 28 26.png");down $nespadbuttonselectsurf[1][1]= _SDL_Rect_Create($nespadrect.x+95, $nespadrect.y+177, 28, 26) $nespadbuttonselectsurf[2][0]= _IMG_Load($graphicpath&"\nes-select-left 58 140 25 29.png");left $nespadbuttonselectsurf[2][1]= _SDL_Rect_Create($nespadrect.x+58, $nespadrect.y+140, 25, 29) $nespadbuttonselectsurf[3][0]= _IMG_Load($graphicpath&"\nes-select-right 133 141 26 26.png");right $nespadbuttonselectsurf[3][1]= _SDL_Rect_Create($nespadrect.x+133, $nespadrect.y+141, 26, 26) $nespadbuttonselectsurf[4][0]= _IMG_Load($graphicpath&"\nes-select-select 228 178 30 12.png");select button highlight $nespadbuttonselectsurf[4][1]= _SDL_Rect_Create($nespadrect.x+228, $nespadrect.y+178, 30, 12) $nespadbuttonselectsurf[4][2]= _IMG_Load($graphicpath&"\nes-select-label 205 125 73 13.png");select text label $nespadbuttonselectsurf[4][3]= _SDL_Rect_Create($nespadrect.x+205, $nespadrect.y+125, 73, 13) $nespadbuttonselectsurf[5][0]= _IMG_Load($graphicpath&"\nes-select-select 228 178 30 12.png");start button highlight $nespadbuttonselectsurf[5][1]= _SDL_Rect_Create($nespadrect.x+306, $nespadrect.y+178, 30, 12) $nespadbuttonselectsurf[5][2]= _IMG_Load($graphicpath&"\nes-select-start-label 295 125 61 13.png");start text label $nespadbuttonselectsurf[5][3]= _SDL_Rect_Create($nespadrect.x+289, $nespadrect.y+125, 61, 13) $nespadbuttonselectsurf[6][0]= _IMG_Load($graphicpath&"\nes-select-B.png");button B $nespadbuttonselectsurf[6][1]= _SDL_Rect_Create($nespadrect.x+413, $nespadrect.y+170, 25, 24) $nespadbuttonselectsurf[6][2]= _IMG_Load($graphicpath&"\nes-select-B-label 447 224 15 14.png");B text label $nespadbuttonselectsurf[6][3]= _SDL_Rect_Create($nespadrect.x+447, $nespadrect.y+223, 15, 14) $nespadbuttonselectsurf[7][0]= _IMG_Load($graphicpath&"\nes-select-B.png");A button highlight $nespadbuttonselectsurf[7][1]= _SDL_Rect_Create($nespadrect.x+491, $nespadrect.y+170, 25, 24) $nespadbuttonselectsurf[7][2]= _IMG_Load($graphicpath&"\nes-select-A-label 524 223 15 15.png");A text label $nespadbuttonselectsurf[7][3]= _SDL_Rect_Create($nespadrect.x+524, $nespadrect.y+223, 15, 15) EndFunc;_cc_nesgui_selectiondefine(byref $nespadbuttonselectsurf, byref $nespadrect)( ; Get width and Height from a SDL Surface func _cc_surfget($surf, byref $w, byref $h) $struct= DllStructCreate($tagSDL_SURFACE, $surf) $w= DllStructGetData($struct, "w") $h= DllStructGetData($struct, "h") $struct= 0 EndFunc;_cc_surfget($surf, byref $w, byref $h) ; _cc_controlchanged() compairs the current controls to the user control file on disk func _cc_controlchanged($control, $player, $g_cc_controldatamax, $controlinput) local $controlmax= ubound($control) local $control_temp= _cc_loadcontrols($g_cc_controlsavepath&$g_cc_controlsavefilename&$player&".txt", $controlmax, $g_cc_controldatamax) for $i= 0 to $controlmax-1 for $ii= 0 to $g_cc_controldatamax-1 if $control[$i][0]= 0 then if _GUICtrlHotkey_GetHotkeyCode($controlinput[$i][1])<> $control_temp[$i][$ii] then return 1 else if $control[$i][$ii]<> $control_temp[$i][$ii] then return 1 endif next;$ii next;$i return 0 EndFunc;_cc_controlchanged($control, $player, $g_cc_controldatamax) ; returns a joystick object func _cc_openjoystick(byref $joystick, $joystickid, byref $joystickbuttons, byref $joystickaxes, byref $joystickhats) _SDL_JoystickClose($joystick) $joystick= 0 $joystickbuttons= -1 $joystickaxes= -1 $joystickhats= -1 if $joystickid> 0 then;joystick $joystick= _SDL_JoystickOpen($joystickid-1);b/c joystickid is 1 greater to allow for keyboard in the combobox $joystickbuttons= _SDL_JoystickNumButtons($joystick) $joystickaxes= _SDL_JoystickNumAxes($joystick) $joystickhats= _SDL_JoystickNumHats($joystick) endif return $joystick EndFunc;_cc_openjoystick($joystickid, byref $joystickbuttons, byref $joystickaxes, byref $joystickhats) ; $rect is for a SDL_Rect, however if $rect_y<> default then $rect is treated as $rect_x func _cc_mouseoverrect($mousex, $mousey, $rect, $rect_y= default, $rect_w= default, $rect_h= default) if $rect_y= default then if $mousex> $rect.x-1 and $mousex< $rect.x+$rect.w+1 then if $mousey> $rect.y-1 and $mousey< $rect.y+$rect.h+1 then return 1 endif endif else if $mousex> $rect-1 and $mousex< $rect+$rect_w+1 then if $mousey> $rect_y-1 and $mousey< $rect_y+$rect_h+1 then return 1 endif endif endif return 0 EndFunc;_cc_mouseoverrect($x, $y, $w, $h) func _cc_deletecontrolinput(byref $controlinput, byref $control) ;if $control[0][0]= 0 then for $i= 0 to ubound($control)-1 _GUICtrlHotkey_Delete($controlinput[$i][1]) next ;endif EndFunc;_cc_deletecontrolinput(byref $controlinput, byref $control) ; uses the first control type to determine guihotkey controls or input fields func _cc_createcontrolinput(byref $controlinput, $control, $hgui, $guirect) if $control[0][0]= 0 then;hotkey controls for $i= 0 to ubound($controlinput)-1 guictrldelete($controlinput[$i][1]) $controlinput[$i][1]= _GUICtrlHotkey_Create($hgui, $guirect.w-124, $guirect.h+($i*25), 121, 25) next else;input fields for joystick controls for $i= 0 to ubound($controlinput)-1 guictrldelete($controlinput[$i][1]);delete input field $controlinput[$i][1]= guictrlcreateinput("", $guirect.w-124, $guirect.h+($i*25), 121, 25) guictrlsendmsg(-1, $EM_SETREADONLY, 1, 0);read-only next endif EndFunc;_cc_createcontrolinput(byref $controlinput, $control, $hgui, $guirect) ; First time I've done this so I might be explaining wrong! ; Adapted from Mat's GUIHotkey.au3 to produce a _ispressed() hex keycode ; $keycode : keycode > 255 will have it's key modifier attributes removed ; returns a single _ispressed() keycode func _cc_getkeycode($keycode) Local $iLoByte= $keycode if $keycode> 255 then Local $iHiByte = BitShift($keycode, 8) $iLoByte = BitAND($keycode, 0xFF) endif return hex($iLoByte) EndFunc;_cc_getkeycode($keycode) ; clear the control object func _cc_clearcontrols(byref $control) for $i= 0 to ubound($control)-1 for $ii= 0 to $g_cc_controldatamax-1 $control[$i][$ii]= 0 next next EndFunc;_cc_clearcontrols(byref $control)Simple Example
      #include "configure controls udf.au3" global $debug= 0 test_main() func test_main() local $players= 3 local $controlmax= 8, $controldatamax= 3 local $player[$players][3];control, x, y ;AutoIt options opt("GUICloseOnESC", 0);disable escape closing AutoIt dialog opt("GUIResizeMode", $GUI_DOCKALL);force consistent control spacing of gui controls ;Windows GUI with SDL $hgui= guicreate(@scriptname, 850, 600, default, default, bitor($WS_MAXIMIZEBOX, $WS_MINIMIZEBOX));$WS_SIZEBOX if $debug= 0 then EnvSet("SDL_WINDOWID", $hgui);remark this to create AutoIt window and recieve error messages from AutoIt guisetstate();show screen hgui, screen window ;init SDL _SDL_Init_image() _SDL_Init($_SDL_INIT_EVERYTHING) ;SDL Video Surface $screen $screen= _SDL_SetVideoMode(850, 600, 0, $_SDL_SWSURFACE);bitor($_SDL_SWSURFACE, $_SDL_RESIZABLE) local $joysticks= _SDL_NumJoysticks(); local $joystickobj[$joysticks] if _configurecontrols($hgui, $screen, $players)= 1 then for $i= 0 to $players-1 $player[$i][0]= _cc_loadcontrols($g_cc_controlsavepath&$g_cc_controlsavefilename&$i&".txt", $controlmax, $controldatamax) $control= $player[0][0] if $control[0][0]> 0 then $joystickobj[$control[0][0]-1]= _SDL_JoystickOpen($control[0][0]-1) else;keyboard convert saved keypresses to _ispressed hex codes for $ii= 0 to $controlmax-1 $control[$ii][2]= _cc_getkeycode($control[$ii][2]) next $player[0][0]= $control endif next local $label= guictrlcreatelabel("Press the control assigned to 'Up', to exit", 15, 15) do if $control[0][0]= 0 then if _ispressed($control[0][2]) then exitloop else _SDL_JoystickUpdate($joystickobj[$control[0][0]-1]);update the joystick in question switch $control[0][1] case $buttontype[$e_button][0] to $buttontype[$e_button][1] if _SDL_JoystickGetButton($joystickobj[$control[0][0]-1], $control[0][2])> 0 then exitloop case $buttontype[$e_axis][0] to $buttontype[$e_axis][1];axis $axis= _SDL_JoystickGetAxis($joystickobj[$control[0][0]-1], $control[0][1]-$buttontype[$e_axis][0]) if $control[0][2]< 0 then if $axis< $control[0][2] - 1 then exitloop else if $axis> $control[0][2] - 1 then exitloop endif case $buttontype[$e_hat][0] to $buttontype[$e_hat][1];hat $hat= _SDL_JoystickGetHat($joystickobj[$control[0]-1], $control[0][1]-$buttontype[$e_hat][0]) if $hat= $control[0][2] then exitloop endswitch endif until guigetmsg()= $gui_event_close endif ;close systems If $__SDL_DLL <> -1 Then _SDL_Quit();"Once upon a time... You saw me ;)" If $__SDL_DLL_image <> -1 Then _SDL_Shutdown_image() EndFunc;main()Tank Player Example:Tank.au3

      #include <Array.au3>;_arraydisplay() #include "configure controls udf.au3" #include "tank.h.au3" global $debug= 0 ; AutoIt options opt("GUICloseOnESC", 0);disable escape closing AutoIt dialog main() func main() makeconsole(); create a console gui ;then make transpartent gui main dialog local $hgui = GUICreate("Tank", @DesktopWidth, @DesktopHeight, 0, 0, $WS_POPUP, $WS_EX_LAYERED) _WinAPI_SetLayeredWindowAttributes($hgui, 0x000000, 255);transparency of main screen $hgui, black, 100%transparent if $debug= 0 then EnvSet("SDL_WINDOWID", $hgui);Attaches the next call to _SDL_SetVideoMode() surface to $hgui, idk really ; $debug turns off the attachment to the SDL Video Surface, and then gives us 2 windows 1 for the $hgui and 1 for the SDL Video Surface (I think). This will allow SciTE or whatever to pin point the errors and return them rather then just hang the script. ; Now $debug is a useful variable b/c if you ever need to detect window active in say a nested function environment then you can also check against $debug to toggle the check of active b/c in debug mode you'll have 2 ; windows, $hgui might not be the window you need it to be, when debuging whatever problem you are debuging. $debug can be used to easily avoid this problem. if(winactive($hgui) or $debug= 1) _SDL_Startup_sge() _SDL_Init_image() _SDL_Init($_SDL_INIT_EVERYTHING) local $screen = _SDL_SetVideoMode(@DesktopWidth, @DesktopHeight, 32, $_SDL_HWSURFACE);$screen is now the SDL Video Surface _AutoItObject_Startup(0) for $i= 0 to $players-1 $otank[$i]= tankobject() next local $tank_controlnames[]= ["Forward", "Reverse", "Left", "Right", "Nitro", "Jump", "Drill", "a"] loadplayercontrols() maketrig() loadpics() $redraw= 1 guisetstate();main screen turn on while 1 switch guigetmsg() case $gui_event_close exitloop case $fileexit exitloop case $fileconfigurecontrols winsetstate($hguiconsole, "", @sw_hide);the console doesn't work in the next dialog _WinAPI_SetLayeredWindowAttributes($hgui, 0x000001, 255);transparency to color not in configure controls dialog _configurecontrols($hgui, $screen, $players, $tank_controlnames);dialog for players to setup controls loadplayercontrols();reload the player control files _WinAPI_SetLayeredWindowAttributes($hgui, 0x000000, 255);transparency back to colorblack winsetstate($hguiconsole, "", @sw_show); endswitch _SDL_FillRect($screen, 0, $colorblack);clear the screen surface for $i= 0 to $players-1 $control= $a_tankcontrol[$i] tankcontrols($otank[$i], $i) $otank[$i].loopactions() $otank[$i].draw($screen, $i) next _SDL_Flip($screen);update the screen surface wend;main loop _SDL_Quit() _SDL_Shutdown_image() _SDL_Shutdown_sge() EndFunc;main() func loadplayercontrols() for $i= 0 to $players-1 $control= _cc_loadcontrols($g_cc_controlsavepath & $g_cc_controlsavefilename & $i & ".txt", $controlmax, $controldatamax) for $ii= 0 to $controlmax-1 if $control[$ii][0]> 0 then $joystickobj[$i]= _SDL_JoystickOpen($control[$ii][0]-1) consolewrite("Joystick "&$control[$i][0]-1& "opened") exitloop else;convert keystrokes $control[$ii][2]= _cc_getkeycode($control[$ii][2]) endif next $a_tankcontrol[$i]= $control next EndFunc;loadplayercontrols() func makeconsole($startup_output= "Hello world.") $hguiconsole= guicreate("Tank", $consolew, $consoleh) $filemenu= guictrlcreatemenu("File") $fileexit= guictrlcreatemenuitem("Exit", $filemenu) $g_consoleedit= guictrlcreateedit($startup_output, 10, 20, 300, 80) $fileconfigurecontrols= guictrlcreatemenuitem("Configure Controls", $filemenu) guictrlsendmsg($g_consoleedit, $EM_SETREADONLY, 1, 0);read-only guisetstate() EndFunc;makeconsole()Tank.h.au3
      #include-once #include "tank.global.au3" #include "configure controls udf.au3" func consoleout($output) ; insert new line at end of edit control $iEnd = StringLen(GUICtrlRead($g_consoleedit));Melba23 ref: http://www.autoitscript.com/forum/topic/110948-add-text-to-edit-box-and-scroll-it-down/#entry778671 _GUICtrlEdit_SetSel($g_consoleedit, $iEnd, $iEnd) _GUICtrlEdit_Scroll($g_consoleedit, $SB_SCROLLCARET) guictrlsetdata($g_consoleedit, @crlf & $output, 1) EndFunc;consoleout($output) func loadpics() $path= @scriptdir & "\..\graphics\" consoleout("Load graphics from: " & $path&@crlf) local $w= 0, $h= 0 for $a= 0 to 180-1 for $i= 0 to $tank_tredframemax-1 $tank_tredl[$a][$i]= _SDL_LoadBMP($path & "lefttred\"&$a&"_"&$i&".bmp") _SDL_SetColorKey($tank_tredl[$a][$i], $_SDL_SRCCOLORKEY, _SDL_MapRGB($tank_tredl[$a][$i], 0x00, 0x00, 0x00)) $tank_tredr[$a][$i]= _SDL_LoadBMP($path & "righttred\"&$a&"_"&$i&".bmp") _SDL_SetColorKey($tank_tredr[$a][$i], $_SDL_SRCCOLORKEY, _SDL_MapRGB($tank_tredl[$a][$i], 0x00, 0x00, 0x00)) next;tred frame $tank_body[$a]= _SDL_LoadBMP($path & "body\"&$a&".bmp") _SDL_SetColorKey($tank_body[$a], $_SDL_SRCCOLORKEY, _SDL_MapRGB($tank_body[$a], 0x00, 0x00, 0x00)) for $i= 0 to $tank_drillframemax-1 $tank_drill[$a][$i]= _SDL_LoadBMP($path & "drill\"&$a&"_"&$i&".bmp") _SDL_SetColorKey($tank_drill[$a][$i], $_SDL_SRCCOLORKEY, _SDL_MapRGB($tank_drill[$a][$i], 0x00, 0x00, 0x00)) next;drill frame next;angle for $i= 0 to $tank_personmax-1 $tank_person[0][$i]= _SDL_LoadBMP($path & "person\"&$i&".bmp") _SDL_SetColorKey($tank_person[0][$i], $_SDL_SRCCOLORKEY, _SDL_MapRGB($tank_person[0][$i], 0x00, 0x00, 0x00)) next _cc_surfget($tank_person[0][0], $w, $h) if $players> 1 then for $i= 1 to $players-1 $colormask= $i*25 if $colormask> 255 then while $colormask> 255 $colormask-= 255 wend endif for $ii= 0 to $tank_personmax-1 $tank_person[$i][$ii]= _SDL_CreateRGBSurface($_SDL_HWSURFACE, $w, $h, 32, $colormask, $colormask, $colormask, 255) _SDL_BlitSurface($tank_person[0][$ii], 0, $tank_person[$i][$ii], 0) next next endif consoleout("Graphics Loaded") EndFunc;end loadpics() func fixa($a) if $a>= 359.9 then $a-= 360; if $a< 0 then $a+= 359.9; return $a EndFunc;end fixa($a) func maketrig() for $a= 0 to 359 $mycos[$a]= cos($a*3.1416/180) $mysin[$a]= sin($a*3.1416/180) next EndFunc;end maketrig() func tankcontrols(byref $tankobj, $player) local $action= -1 local $control= $a_tankcontrol[$player] _SDL_JoystickUpdate($joystickobj[$player]) for $i= 0 to $controlmax-1 $action= -1 if $control[$i][0]> 0 then;joystick ;_SDL_JoystickUpdate($joystickobj[$player]) ;joystick axis switch $control[$i][1];button type case $buttontype[$e_button][0] to $buttontype[$e_button][1];gamepad button if _SDL_JoystickGetButton($joystickobj[$player], $control[$i][2])> 0 then $action= $i endif case $buttontype[$e_axis][0] to $buttontype[$e_axis][1];axis $axis= _SDL_JoystickGetAxis($joystickobj[$player], $control[$i][1]-$buttontype[$e_axis][0]) if $control[$i][2]< 0 then if $axis< $control[$i][2] - 1 then $action= $i else if $axis> $control[$i][2] - 1 then $action= $i endif case $buttontype[$e_hat][0] to $buttontype[$e_hat][1];hat $hat= _SDL_JoystickGetHat($joystickobj[$player], $control[$i][1]-$buttontype[$e_hat][0]) if $hat= $control[$i][2] then $action= $i endswitch else;keyboard if _ispressed($control[$i][2], $hdll) then $action= $i endif endif;joystick or keyboard if $action> -1 then if $action= $e_tankctrl_forward then $tankobj.control_forward= 1 endif if $action= $e_tankctrl_backward then $tankobj.control_backward= 1 endif if $action= $e_tankctrl_left then $tankobj.control_left= 1 endif if $action= $e_tankctrl_right then $tankobj.control_right= 1 endif if $action= $e_tankctrl_nitro then $tankobj.control_nitro= 1 endif if $action= $e_tankctrl_jump then $tankobj.control_jump= 1 endif if $action= $e_tankctrl_drill then $tankobj.control_drill= 1 endif endif next;control EndFunc;end tankobjectcontrols()Tankclass.au3
      #include-once #include "tank.global.au3" #include "configure controls udf.au3" func tankobject($iStartup = False) local $oObj = _AutoItObject_Create() _AutoItObject_AddMethod($oObj, "draw", "tankobjectdraw") _AutoItObject_AddMethod($oObj, "loopactions", "tankobjectloopactions") _AutoItObject_AddProperty($oObj, "x", $ELSCOPE_Public, random(32, @DesktopWidth-32, @DesktopHeight-32)) _AutoItObject_AddProperty($oObj, "y", $ELSCOPE_Public, random(32, 359)) _AutoItObject_AddProperty($oObj, "drillframe", $ELSCOPE_Public, 0) _AutoItObject_AddProperty($oObj, "angle", $ELSCOPE_Public, random(0, 359)) _AutoItObject_AddProperty($oObj, "acc", $ELSCOPE_Public, 0) _AutoItObject_AddProperty($oObj, "v", $ELSCOPE_Public, 0) _AutoItObject_AddProperty($oObj, "anglev", $ELSCOPE_Public, 0) _AutoItObject_AddProperty($oObj, "surf", $ELSCOPE_Public, 0) _AutoItObject_AddProperty($oObj, "tredframel", $ELSCOPE_Public, 0) _AutoItObject_AddProperty($oObj, "tredframer", $ELSCOPE_Public, 0) _AutoItObject_AddProperty($oObj, "distancetraveled", $ELSCOPE_Public, 100000) _AutoItObject_AddProperty($oObj, "distancetraveledl", $ELSCOPE_Public, 100000) _AutoItObject_AddProperty($oObj, "distancetraveledr", $ELSCOPE_Public, 100000) _AutoItObject_AddProperty($oObj, "nitroup", $ELSCOPE_Public, 0) _AutoItObject_AddProperty($oObj, "jumpy", $ELSCOPE_Public, 0) _AutoItObject_AddProperty($oObj, "jumpa", $ELSCOPE_Public, 0) _AutoItObject_AddProperty($oObj, "jumpv", $ELSCOPE_Public, 0) _AutoItObject_AddProperty($oObj, "updown", $ELSCOPE_Public, 0) ;controls local $a_control[$controlmax][$controldatamax] _AutoItObject_AddProperty($oObj, "a_control", $ELSCOPE_Public, $a_control) _AutoItObject_AddProperty($oObj, "control_forward") _AutoItObject_AddProperty($oObj, "control_backward") _AutoItObject_AddProperty($oObj, "control_left") _AutoItObject_AddProperty($oObj, "control_right") _AutoItObject_AddProperty($oObj, "control_drill") _AutoItObject_AddProperty($oObj, "control_jump") _AutoItObject_AddProperty($oObj, "control_nitro") $path= @scriptdir & "\..\graphics\" $oObj.surf= _SDL_LoadBMP($path & "drill\"&0&"_"&0&".bmp");create a tank surface to construct the tank on _SDL_SetColorKey($oObj.surf, $_SDL_SRCCOLORKEY, _SDL_MapRGB($oObj.surf, 0x00, 0x00, 0x00)) if $iStartup then $oObj.Startup return $oObj EndFunc;end tankobject func tankobjectdraw($oself, $screen, $player) _SDL_FillRect($oself.surf, 0, $colorblack);clear the tank surface $angleint= int($oself.angle/2) _SDL_BlitSurface($tank_tredl[$angleint][$oself.tredframel], 0, $oself.surf, 0);left tred _SDL_BlitSurface($tank_tredr[$angleint][$oself.tredframer], 0, $oself.surf, 0);right tred _SDL_BlitSurface($tank_body[$angleint], 0, $oself.surf, 0) _SDL_BlitSurface($tank_drill[$angleint][$oself.drillframe], 0, $oself.surf, 0) $personframe= int($oself.angle/360*$tank_personmax) _SDL_BlitSurface($tank_person[$player][$personframe], 0, $oself.surf, 0);draw person rider if $oself.jumpy< 0 then;surf,x,y,r,c,al _sge_FilledCircleAlpha($screen, $oself.x+32, $oself.y+48, 10+($oself.jumpy/6), _SDL_MapRGB($screen, 10, 10, 10), 100-($oself.jumpy)); _SDL_BlitSurface($oself.surf, 0, $screen, _SDL_Rect_Create($oself.x, $oself.y+$oself.jumpy, 64, 64));draw the tank surface else _SDL_BlitSurface($oself.surf, 0, $screen, _SDL_Rect_Create($oself.x, $oself.y, 64, 64));draw the tank surface endif;endif jumpy< 0 EndFunc;end draw() func tankobjectloopactions($oself) $oself.distancetraveledl= $oself.distancetraveledl+$oself.v+(17*$oself.anglev*3.1416/180) $oself.distancetraveledr= $oself.distancetraveledr+$oself.v+(-17*$oself.anglev*3.1416/180) $oself.distancetraveled= $oself.distancetraveled+$oself.v if $oself.jumpy> -1 then if $oself.control_forward= 1 then;26 up arrow $oself.acc= $oself.acc+.0009 $oself.v= $oself.v+$oself.acc else $oself.v= $oself.v*.9 if $oself.acc> 0 then $oself.acc= $oself.acc*.0005 endif if $oself.control_backward= 1 then;28 down arrow ;$oself.x-= $mysin[$tank_angle] $oself.x= $oself.x- $mysin[$oself.angle] $oself.y= $oself.y+ $mycos[$oself.angle] $oself.distancetraveledl= $oself.distancetraveledl-1 $oself.distancetraveledr= $oself.distancetraveledr-1 endif if $oself.control_left= 1 then;25 left arrow if $oself.anglev> 0 then $oself.anglev= 0 $oself.anglev= $oself.anglev-.1 $oself.angle= $oself.angle+$oself.anglev endif if $oself.control_right= 1 then;27 right arrow if $oself.anglev< 0 then $oself.anglev= 0 $oself.anglev= $oself.anglev+.1 $oself.angle= $oself.angle+$oself.anglev endif if $oself.control_drill= 1 then;44 'd' $oself.drillframe= $oself.drillframe+1 if $oself.drillframe> $tank_drillframemax-1 then $oself.drillframe= $oself.drillframe-$tank_drillframemax endif if $oself.control_nitro= 1 then;0x4E 'n' if $oself.nitroup= 0 then $oself.nitroup= 5 endif endif if $oself.control_jump= 1 then $oself.control_jump= 0 if $oself.jumpy> -1 and $oself.updown= 0 then $oself.jumpy= -45 endif endif else $oself.jumpy= $oself.jumpy+2 endif;jumpy= 0 if $oself.nitroup> 0 then $oself.control_nitro= 0 $oself.v= $oself.v*1.2 $oself.nitroup= $oself.nitroup-1 endif;endif $nitroup> 50 if $oself.x< -31 then $oself.x= $oself.x+@DesktopWidth if $oself.x> @DesktopWidth then $oself.x= $oself.x-@DesktopWidth if $oself.y< -31 then $oself.y= $oself.y+@DesktopHeight if $oself.y> @DesktopHeight+31 then $oself.y= $oself.y-@DesktopHeight if $oself.distancetraveled< 0 then $oself.distancetraveled= $oself.distancetraveled+100000 if $oself.distancetraveledl< 0 then $oself.distancetraveledl= $oself.distancetraveledl+100000 if $oself.distancetraveledr< 0 then $oself.distancetraveledr= $oself.distancetraveledr+100000 $oself.tredframel= $tank_tredframemax-1-mod(int($oself.distancetraveledl/$tank_tredframemax), $tank_tredframemax) $oself.tredframer= $tank_tredframemax-1-mod(int($oself.distancetraveledr/$tank_tredframemax), $tank_tredframemax) if $oself.control_left= 0 and $oself.control_right= 0 then $oself.anglev= 0 $oself.control_forward= 0 $oself.control_backward= 0 $oself.control_left= 0 $oself.control_right= 0 $oself.control_drill= 0 $oself.control_jump= 0 while $oself.angle>= 359.9 $oself.angle= $oself.angle-360; wend while $oself.angle< 0 $oself.angle= $oself.angle+359.9; wend if $oself.acc> 0 then;friction $oself.acc= $oself.acc-.01 else $oself.acc= 0 endif;end friction $oself.x= $oself.x- ($mysin[int($oself.angle)])*($oself.v) $oself.y= $oself.y+ ($mycos[int($oself.angle)])*($oself.v) EndFunc;end tankloopactions()Tank.global.au3
      #include-once #Include "Include Lib\SDL v14\SDL.au3" #include "Include Lib\AutoItObject\AutoitObject.au3" #Include "Include Lib\SDL v14\SDL_sge.au3" #include <GUIConstantsEx.au3> #Include <WinAPI.au3> #include <WindowsConstants.au3> #Include <Color.au3> #Include <misc.au3> #include <GUIConstantsEx.au3> #include <EditConstants.au3> #Include <GUIEdit.au3> #Include <ScrollBarConstants.au3> global $hgui= 0 global $players= 3 global $otank[$players] global $a_tankcontrol[$players] global $joystickobj[$players] global $controlmax= 8, $controldatamax= 3 global $colorblack= 0 global $tank_tredframemax= 8, $tank_drillframemax= 3 global $tank_tredl[180][8], $tank_tredr[180][8], $tank_body[180], $tank_drill[180][3] global $tank_personmax= 32 global $tank_person[$players][$tank_personmax] global enum $e_tankctrl_forward= 0, $e_tankctrl_backward= 1, $e_tankctrl_left= 2, $e_tankctrl_right= 3, $e_tankctrl_nitro= 4, $e_tankctrl_jump= 5, $e_tankctrl_drill= 6 global $mycos[361], $mysin[361] global $tank_control_forward= 0 global $tank_control_backward= 0 global $tank_control_left= 0 global $tank_control_right= 0 global $tank_control_drill= 0 global $tank_control_jump= 0 global $hdll= dllopen("user32.dll") ;console window for tank global $consolew= 320, $consoleh= 200 global $hguiconsole= 0 global $filemenu= 0 global $fileexit= 0 global $g_consoleedit= 0 global $fileconfigurecontrols= 0 #include "tankclass.au3"Both tank and configure controls have a graphics pack. It's best to just download the Source Folder.If you like this idea, I encourage you to say something. It's a good way to keep me working on this.
      I think I dropped this tank project for at least a year.
    • By kayser2008
      good afternoon
      there is some function in AutoIT like (_BlockInputEx) but joystick to lock the buttons of the joystick you want?
      thank you
  • Create New...