smstroble Posted December 30, 2007 Share Posted December 30, 2007 Script Joy v0.6.0 New: Main GUI 99% Complete Options GUI 90% Complete -Axis view -Buttons pressed -Deadzone Bind keys to joy buttons Bind key to POV directions ToDo: Ctrl-Alt-Shift-Win Modifiers on POV Bind mouse to Axis mousespeed adjust binds Minimize to tray Program specific settings Device specific settings Multiple joysticks at same time Improve GUI eyecandy Global Sensitivity (Possible?) Global Range (Possible?) Global deadzone (Possible?) Detect device info Multi key combination <Something else here> Known Bugs: Does not work with some maximized games (eg MAME) [Anyone know how to fix this?] Credit someone for joy.au3, ill edit when i find the post. [autoit]#include <GUIConstants.au3> Dim $checkbox[14];init checkbox array Dim $Dot[3];init dot array Dim $Button[14] Dim $ctrlcheck[14] Dim $altcheck[14] Dim $shiftcheck[14] Dim $wincheck[14] Dim $axis[6] dim $POV[4] Dim $buttonhold[20] $deadzone = 0 $POVprev = 0 $DefaultDeadzone = 3000 ;Distance from center which is considered centered 0 = No deadzone, 32767 = All deadzone [Default] $diag = 0 ;raw joy input window switch (0 = off, 1 = on) $joy = _JoyInit() If $diag Then ;Diag GUI init $diaggui = GUICreate("Joystick Test", 100, 150, 900) $h = GUICtrlCreateLabel("", 10, 10, 290, 290) GUISetState() EndIf #region Main $main = GUIcreate("Script Joy v0.6.0", 470, 386) $Device = GUICtrlCreateCombo("Select Device", 160+150, 8+16, 145, 25) ;device specific commands (maby later) GUICtrlSetState(-1, @SW_DISABLE) $Profile = GUICtrlCreateCombo("Select Profile", 160+150, 32+16, 145, 25) $Startprog = GUICtrlCreateButton("Start Program", 160+150, 56+16, 137, 25, 0) $Axis[0] = GUICtrlCreateCombo("X Axis", 160+150, 144-24, 145, 25) ;Axis combo drop boxes $Axis[1] = GUICtrlCreateCombo("Y Axis", 160+150, 168-24, 145, 25) $Axis[2] = GUICtrlCreateCombo("Z Axis", 160+150, 192-24, 145, 25) $Axis[3] = GUICtrlCreateCombo("R Axis", 160+150, 216-24, 145, 25) $Axis[4] = GUICtrlCreateCombo("U Axis", 160+150, 240-24, 145, 25) $Axis[5] = GUICtrlCreateCombo("V Axis", 160+150, 264-24, 145, 25) For $i = 0 to 13;Buttons $ctrlcheck[$i] = GUICtrlCreateCheckbox("Ctrl", 8, 24*($i+1)-2) ;ctrl check box $altcheck[$i] = GUICtrlCreateCheckbox("Alt", 44, 24*($i+1)-2) ;alt check box $shiftcheck[$i] = GUICtrlCreateCheckbox("Shift", 77, 24*($i+1)-2) ;shift check box $wincheck[$i] = GUICtrlCreateCheckbox("Win", 118, 24*($i+1)-2) ;win check box $Button[$i] = GUICtrlCreateCombo("Button " & $i+1, 8+150, 24*($i+1), 137, 25, $CBS_DROPDOWNLIST + $CBS_AUTOHSCROLL + $WS_VSCROLL);combo drop box Next ;POV drop boxes $POV[0] = GUICtrlCreateCombo("POV Up", 160+150+36, 264+20, 71, 25) $POV[3] = GUICtrlCreateCombo("POV Left", 160+150, 264+44, 71, 25) $POV[1] = GUICtrlCreateCombo("POV Right", 160+150+73, 264+44, 73, 25) $POV[2] = GUICtrlCreateCombo("POV Down", 160+150+36, 264+67, 71, 25) initcomboboxs() $Label1 = GUICtrlCreateLabel("Buttons:", 8, 8, 43, 15) $Label2 = GUICtrlCreateLabel("Axis:", 160+150, 128-28, 26, 15) $Label3 = GUICtrlCreateLabel("POV:", 160+150, 264, 26, 15) $Filemenu = GUICtrlCreateMenu("&File") $joyselect = GUICtrlCreateMenuItem("Joystick", $Filemenu) GUICtrlSetState(-1, $GUI_DISABLE) $mItemOptions = GUICtrlCreateMenuItem("Options", $Filemenu) $mItemExit = GUICtrlCreateMenuItem("Exit", $Filemenu) GUISetState() While 1 $mmsg = GUIGetMsg() If $mmsg = $GUI_EVENT_CLOSE Or $mmsg = $mItemExit Then Exit ElseIf $mmsg = $mItemOptions Then GUISetState(@SW_DISABLE, $main) options() EndIf For $i = 0 to 5 ;Axis If $mmsg = $axis[$i] Then IniWrite("binds.ini", "Joy0", "axis" & $i, Convert(GUICtrlRead($Axis[$i]))) EndIf Next For $i = 0 to 13 ;Buttons If $mmsg = $Button[$i] or $mmsg = $ctrlcheck[$i] or $mmsg = $altcheck[$i] or $mmsg = $shiftcheck[$i] or $mmsg = $wincheck[$i] Then $key = "" If Guictrlread($ctrlcheck[$i]) = $GUI_CHECKED Then $key = $key & "^" EndIf If Guictrlread($altcheck[$i]) = $GUI_CHECKED Then $key = $key & "!" EndIf If Guictrlread($shiftcheck[$i]) = $GUI_CHECKED Then $key = $key & "+" EndIf If Guictrlread($wincheck[$i]) = $GUI_CHECKED Then $key = $key & "#" EndIf $key = $key & convert(GUICtrlRead($Button[$i])) ;MsgBox(0, "", GUICtrlRead($Button[$i])) IniWrite("binds.ini", "Joy0", "Button" & $i, $key) EndIf Next For $i = 0 to 3 ;POV If $mmsg = $POV[$i] Then ;Todo: ;$key = "" ;If Guictrlread($ctrlcheck[$i]) = $GUI_CHECKED Then ; $key = $key & "^" ;EndIf ;If Guictrlread($altcheck[$i]) = $GUI_CHECKED Then ; $key = $key & "!" ;EndIf ;If Guictrlread($shiftcheck[$i]) = $GUI_CHECKED Then ; $key = $key & "+" ;EndIf ;If Guictrlread($wincheck[$i]) = $GUI_CHECKED Then ; $key = $key & "#" ;EndIf ;$key = $key & convert(GUICtrlRead($Axis[$i]))) IniWrite("binds.ini", "Joy0", "POV" & $i, convert(GUICtrlRead($POV[$i]))) EndIf Next Binds() WEnd Func Binds() $joy0 = _GetJoy($joy, 0) For $i = 0 To 13 ;Check 14 buttons (Increase if you add more buttons!) If BitAND(2 ^ $i, $joy0[7]) And BitAND(2 ^ $i, $buttonhold[$i]) = 0 Then ;If button is being pressed, but was not on last check (for efficiency) $key = "" If Guictrlread($ctrlcheck[$i]) = $GUI_CHECKED Then $key = $key & "^" EndIf If Guictrlread($altcheck[$i]) = $GUI_CHECKED Then $key = $key & "!" EndIf If Guictrlread($shiftcheck[$i]) = $GUI_CHECKED Then $key = $key & "+" EndIf If Guictrlread($wincheck[$i]) = $GUI_CHECKED Then $key = $key & "#" EndIf If GUICtrlRead($Button[$i]) <> "Button " & ($i+1) Then $key = $key & convert(GUICtrlRead($Button[$i])) EndIf ;MsgBox(0, "", $key) Send($key) $buttonhold[$i] = BitXOR(2 ^ $i, $buttonhold[$i]) ;Add button to held buttons list ElseIf BitAND(2 ^ $i, $joy0[7]) = 0 And BitAND(2 ^ $i, $buttonhold[$i]) Then ;If button is not being pressed, but was on last check (for efficiency) $buttonhold[$i] = BitXOR(2 ^ $i, $buttonhold[$i]) ;Remove button to held buttons list EndIf Next For $i = 0 To 3 ;Check 4 POV dirs If 9000*$i = $joy0[6] And BitAND(2 ^ $i, $buttonhold[$i+13]) = 0 Then ;If button is being pressed, but was not on last check (for efficiency) $key = "" If Guictrlread($ctrlcheck[$i]) = $GUI_CHECKED Then $key = $key & "^" EndIf If Guictrlread($altcheck[$i]) = $GUI_CHECKED Then $key = $key & "!" EndIf If Guictrlread($shiftcheck[$i]) = $GUI_CHECKED Then $key = $key & "+" EndIf If Guictrlread($wincheck[$i]) = $GUI_CHECKED Then $key = $key & "#" EndIf If GUICtrlRead($Button[$i]) <> "Button " & ($i+1) Then $key = $key & convert(GUICtrlRead($POV[$i])) EndIf ;MsgBox(0, "", $key) Send($key) $buttonhold[$i+13] = BitXOR(2 ^ $i, $buttonhold[$i+13]) ;Add button to held buttons list ElseIf 9000*$i <> $joy0[6] And BitAND(2 ^ $i, $buttonhold[$i+13]) Then ;If button is not being pressed, but was on last check (for efficiency) $buttonhold[$i+13] = BitXOR(2 ^ $i, $buttonhold[$i+13]) ;Remove button to held buttons list EndIf Next EndFunc Func convert($value) $value = StringReplace($value, "}", "{}}") $value = StringReplace($value, "{", "{{}") $value = StringReplace($value, "Left Shift", "{LSHIFT}") $value = StringReplace($value, "Right Shift", "{RSHIFT}") $value = StringReplace($value, "Left CTRL", "{LCTRL}") $value = StringReplace($value, "Right CTRL", "{RCTRL}") $value = StringReplace($value, "Left ALT", "{LALT}") $value = StringReplace($value, "Right ALT", "{RALT}") $value = StringReplace($value, "Left WIN", "{LWIN}") $value = StringReplace($value, "Right WIN", "{RWIN}") $value = StringReplace($value, "^", "{^}") $value = StringReplace($value, "!", "{!}") $value = StringReplace($value, "+", "{+}") $value = StringReplace($value, "#", "{#}") $value = StringReplace($value, "Up", "{Up}") $value = StringReplace($value, "Down", "{Down}") $value = StringReplace($value, "Left", "{Left}") $value = StringReplace($value, "Right", "{Right}") $value = StringReplace($value, "Enter", "{Enter}") $value = StringReplace($value, "Space", "{Space}") $value = StringReplace($value, "Tab", "{TAB}") $value = StringReplace($value, "Backspace", "{Backspace}") $value = StringReplace($value, "Prnt Scrn", "{PRINTSCREEN}") $value = StringReplace($value, "Pause", "{Pause}") $value = StringReplace($value, "Insert", "{Insert}") $value = StringReplace($value, "Delete", "{Delete}") $value = StringReplace($value, "Home", "{Home}") $value = StringReplace($value, "End", "{End}") $value = StringReplace($value, "Page Up", "{PGUP}") $value = StringReplace($value, "Page Dn", "{PGDN}") $value = StringReplace($value, "Play", "{MEDIA_PLAY_PAUSE}") $value = StringReplace($value, "Next", "{MEDIA_NEXT}") $value = StringReplace($value, "Prev", "{MEDIA_PREV}") $value = StringReplace($value, "Stop", "{MEDIA_stop}") $value = StringReplace($value, "Mute", "{VOLUME_MUTE}") $value = StringReplace($value, "Vol Up", "{VOLUME_UP}") $value = StringReplace($value, "Vol Dn", "{VOLUME_DOWN}") return $value EndFunc Func unconvert($value) $value = StringReplace($value, "{}}", "}") $value = StringReplace($value, "{{}", "{") $value = StringReplace($value, "{LSHIFT}", "Left Shift") $value = StringReplace($value, "{RSHIFT}", "Right Shift") $value = StringReplace($value, "{LCTRL}", "Left CTRL") $value = StringReplace($value, "{RCTRL}", "Right CTRL") $value = StringReplace($value, "{LALT}", "Left ALT") $value = StringReplace($value, "{RALT}", "Right ALT") $value = StringReplace($value, "{LWIN}", "Left WIN") $value = StringReplace($value, "{RWIN}", "Right WIN") $value = StringReplace($value, "{^}", "^") $value = StringReplace($value, "{!}", "!") $value = StringReplace($value, "{+}", "+") $value = StringReplace($value, "{#}", "#") $value = StringReplace($value, "{Up}", "Up") $value = StringReplace($value, "{Down}", "Down") $value = StringReplace($value, "{Left}", "Left") $value = StringReplace($value, "{Right}", "Right") $value = StringReplace($value, "{Enter}", "Enter") $value = StringReplace($value, "{Space}", "Space") $value = StringReplace($value, "{TAB}", "Tab") $value = StringReplace($value, "{Backspace}", "Backspace") $value = StringReplace($value, "{PRINTSCREEN}", "Prnt Scrn") $value = StringReplace($value, "{Pause}", "Pause") $value = StringReplace($value, "{Insert}", "Insert") $value = StringReplace($value, "{Delete}", "Delete") $value = StringReplace($value, "{Home}", "Home") $value = StringReplace($value, "{End}", "End") $value = StringReplace($value, "{PGUP}", "Page Up") $value = StringReplace($value, "{PGDN}", "Page Dn") $value = StringReplace($value, "{MEDIA_PLAY_PAUSE}", "Play") $value = StringReplace($value, "{MEDIA_NEXT}", "Next") $value = StringReplace($value, "{MEDIA_PREV}", "Prev") $value = StringReplace($value, "{MEDIA_stop}", "Stop") $value = StringReplace($value, "{VOLUME_MUTE}", "Mute") $value = StringReplace($value, "{VOLUME_UP}", "Vol Up") $value = StringReplace($value, "{VOLUME_DOWN}", "Vol Dn") Dim $out[5] $value = StringReplace($value, "^", "") $out[1] = @extended ;ctrl $value = StringReplace($value, "!", "") $out[2] = @extended ;alt $value = StringReplace($value, "+", "") $out[3] = @extended ;Sift $value = StringReplace($value, "#", "") $out[4] = @extended ;Win $out[0] = $value return $out EndFunc func initcomboboxs();Fill List boxes $list = "" $list = $list & "Up" & "|" $list = $list & "Down" & "|" $list = $list & "Left" & "|" $list = $list & "Right" & "|" $list = $list & "Enter" & "|" $list = $list & "Space" & "|" $list = $list & "Tab" & "|" $list = $list & "Backspace" & "|" $list = $list & "Prnt Scrn" & "|" $list = $list & "Pause" & "|" $list = $list & "Insert" & "|" $list = $list & "Delete" & "|" $list = $list & "Home" & "|" $list = $list & "End" & "|" $list = $list & "Page Up" & "|" $list = $list & "Page Dn" & "|" $list = $list & "Play" & "|" $list = $list & "Next" & "|" $list = $list & "Prev" & "|" $list = $list & "Stop" & "|" $list = $list & "Mute" & "|" $list = $list & "Vol Up" & "|" $list = $list & "Vol Dn" & "|" $list = $list & "Left Shift" & "|" $list = $list & "Right Shift" & "|" $list = $list & "Left CTRL" & "|" $list = $list & "Right CTRL" & "|" $list = $list & "Left ALT" & "|" $list = $list & "Right ALT" & "|" $list = $list & "Left WIN" & "|" $list = $list & "Right WIN" & "|" For $q = 44 to 57 $list = $list & Chr($q) & "|" Next $list = $list & Chr(59) & "|" $list = $list & Chr(61) & "|" $list = $list & Chr(91) & "|" $list = $list & Chr(92) & "|" $list = $list & Chr(93) & "|" $list = $list & Chr(94) & "|" For $q = 96 to 122 $list = $list & Chr($q) & "|" Next $list = $list & Chr(126) for $i = 0 to 13 $Default = unconvert(IniRead("binds.ini", "Joy0", "Button"&$i, "Button " & $i)) GUICtrlSetData($Button[$i], $list, $Default[0]) ;MsgBox(0, $Default[0], "") If $Default[1] Then GUICtrlSetState($ctrlcheck[$i], $GUI_CHECKED) If $Default[2] Then GUICtrlSetState($altcheck[$i], $GUI_CHECKED) If $Default[3] Then GUICtrlSetState($shiftcheck[$i], $GUI_CHECKED) If $Default[4] Then GUICtrlSetState($wincheck[$i], $GUI_CHECKED) Next For $i = 0 to 3 $Default = unconvert(IniRead("binds.ini", "Joy0", "POV"&$i, "POV")) StringReplace($Default[0], "POV", "") If @extended Then ;If a replacement was made GUICtrlSetData($POV[$i], $list) Else GUICtrlSetData($POV[$i], $list, $Default[0]) EndIf Next EndFunc #endregion #region Options GUI Func Options() $Options = GUICreate("ScriptJoy - Options", 450, 300) ;Close button $OKButton = Guictrlcreatebutton("OK", 340, 240, 100, 50) ;Deadzone Slider $deadzone = GUICtrlCreateSlider (200,40,200,20, $TBS_NOTICKS) GUICtrlSetLimit(-1,32767,0) GUICtrlCreateLabel("0% (0)", 200, 60) GUICtrlCreateLabel("100% (62767)", 380, 60) $deadzoneread = GUICtrlCreateLabel("Deadzone: " & $DefaultDeadzone, 200, 25, -1, 14) ;Joy Button Status Check Boxes For $i = 0 to 13 $checkbox[$i] = GUICtrlCreateCheckbox("Button " & $i+1, 8, 16+(20*$i)) GUICtrlSetState(-1, $GUI_DISABLE) Next ;Axis XY $Group1 = GUICtrlCreateGroup("", 112, 26, 68, 75) ;Cool looking box (X-Y Axis) GUICtrlSetBkColor(-1, 0xFFFFFF) ;Change color in box $Dot[0] = GUICtrlCreateLabel("|", 200, 25, 4, 4) ;The DOT! GUIctrlsetfont(-1, -1, 800);BOLD! GUICtrlCreateLabel("|", 112+32, 32+32, 4, 4);Center Dot GUIctrlsetfont(-1, -1, 800);BOLD! Guictrlsetcolor(-1, dec("FF0000"));RED! GUICtrlCreateLabel("X Y Axis", 112, 16, 43, 15) ;So you know what your looking at :-) ;Axis ZR $Group2 = GUICtrlCreateGroup("", 112, 119, 68, 75) GUICtrlSetBkColor(-1, 0xFFFFFF) $Dot[1] = GUICtrlCreateLabel("|", 200, 25, 4, 4) GUIctrlsetfont(-1, -1, 800) GUICtrlCreateLabel("|", 112+32, 125+32, 4, 4) GUIctrlsetfont(-1, -1, 800) Guictrlsetcolor(-1, dec("FF0000")) GUICtrlCreateLabel("Z R Axis", 113, 110, 44, 15) ;Axis UV (Talk about a bad ass controler 3 analog sticks) $Group3 = GUICtrlCreateGroup("", 112, 216, 68, 75) GUICtrlSetBkColor(-1, 0xFFFFFF) $Dot[2] = GUICtrlCreateLabel("|", 200, 25, 4, 4) GUIctrlsetfont(-1, -1, 800) GUICtrlCreateLabel("|", 112+32, 222+32, 4, 4) GUIctrlsetfont(-1, -1, 800) Guictrlsetcolor(-1, dec("FF0000")) GUICtrlCreateLabel("U V Axis", 112, 207, 44, 15) ;POV Hat or D-Pad $Label18 = GUICtrlCreateLabel("POV Hat:", 200, 90, 46, 15) $povdir = GUICtrlCreateLabel("l", 200+46+5, 90, 16, 16) GUIctrlsetfont(-1, -1, -1, -1, "Wingdings") GUISetState(@SW_SHOW) GUICtrlSetData($Deadzone, $DefaultDeadzone);Set deadzone slider $buttonhold = 0 ;Define and clear buttons held (binary format eg 1[2^0] = first button on, 2[2^1] = 2nd button on, 4[2^2] = 3rd, 3[2^0 + 2^1] = 1st and 2nd etc.) $deadzoneprev = $DefaultDeadzone ;Used to see if deadzone slider moved $POVprev = 65535 ;Used to see if POV direction changed While 1 $nMsg = GUIGetMsg(0) ;Get message of GUI messge Query $joy0 = _GetJoy ($joy, 0) ;Query joystick 0 If $GUI_EVENT_CLOSE = $nmsg And $diag = 0 or $nmsg = $OKButton Then GUIDelete($options) ;Someone clicked the red X, tisk tisk GUISetState(@SW_ENABLE, $Main) ;reemable main return Elseif $GUI_Event_CLOSE = $nmsg Then ;Clicked X with diag window open GUIDelete($diaggui) ;Delete diag window $diag = 0 ;Disable diag loop EndIf If GUICtrlRead($deadzone) <> $deadzoneprev Then ;If slider moved GUICtrlSetData($deadzoneread, "Deadzone: " & GUICtrlRead($deadzone)) ;Update readout label $deadzoneprev = GUICtrlRead($deadzone) ;Update check variable EndIf For $i = 0 To 14 ;Check 14 buttons (Increase if you add more buttons!) If BitAND(2 ^ $i, $joy0[7]) And BitAND(2 ^ $i, $buttonhold) = 0 Then ;If button is being pressed, but was not on last check (for efficiency) GUICtrlSetState($checkbox[$i], $GUI_CHECKED) ;toggle check box $buttonhold = BitXOR(2 ^ $i, $buttonhold) ;Add button to held buttons list ElseIf BitAND(2 ^ $i, $joy0[7]) = 0 And BitAND(2 ^ $i, $buttonhold) Then ;If button is not being pressed, but was on last check (for efficiency) GUICtrlSetState($checkbox[$i], $GUI_UNCHECKED) ;toggle Check box $buttonhold = BitXOR(2 ^ $i, $buttonhold) ;Remove button to held buttons list EndIf Next Axis($joy0);update axis dots POV($joy0, $povdir);Update Hat position If $diag Then Diagloop($joy0) ;Diag window loop WEnd EndFunc Func Axis($coor) ;Moves dot for Analog Stick X and Y axis For $i = 0 to 4 step 2;3 axis $xpos = $coor[$i]/65535*64 ;X Position in XY box if $coor[$i] >= 32767-GUICtrlRead($deadzone) And $coor[$i] <= 32767+GUICtrlRead($deadzone) Then $xpos = 32 ;Dead Zone (X) $ypos = $coor[$i+1]/65535*64 ;Y Position in XY box if $coor[$i+1] >= 32767-GUICtrlRead($deadzone) And $coor[$i+1] <= 32767+GUICtrlRead($deadzone) Then $ypos = 32 ;Dead Zone (Y) If $i = 0 Then Guictrlsetpos($Dot[0], 112+$xpos, 32+$ypos);XY axis dot adjustment Elseif $i = 2 Then Guictrlsetpos($Dot[1], 112+$xpos, 125+$ypos);ZR axis dot adjustment Else Guictrlsetpos($Dot[2], 112+$xpos, 222+$ypos);UV axis dot adjustment EndIf next EndFunc Func POV($dir, $povdir) If $dir[6] <> $POVprev Then ;I dislike flickering.. :-) $POVprev = $dir[6] Switch $dir[6] Case 65535 GUICtrlSetData($povdir, "l");Center Case 27000 GUICtrlSetData($povdir, " MUHAHAHAHAHA Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now