#include <Array.au3>
#include <GuiComboBox.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
;By Corgano
;Updated by Funtime60
; Script Start - Add your code below here
Global $usbIDs = ""
If not FileExists("usb.ids") Then InetGet("I CAN'T POST LINKS YET GET THESE FROM THE ORIGINAL, SORRY", "usb.ids")
$usbIDs = FileRead("usb.ids")
If not FileExists("hidtrace.exe") Then InetGet("I CAN'T POST LINKS YET GET THESE FROM THE ORIGINAL, SORRY", "hidtrace.exe")
If not FileExists("hidtrace.exe") Then
MsgBox(0, "ERROR", "This program acts as a wrapper for and requires hidtrace.exe to work."&@CRLF&"Attempts to automaticly download it has failed. Please download hidtrace.exe from"&@CRLF&"I CAN'T POST LINKS YET GET THESE FROM THE ORIGINAL, SORRY"&@CRLF&" and place it in the same folder as this program and run again."&@CRLF&@CRLF&"(The link has been copied to clipboard)")
Exit
EndIf
OnAutoItExitRegister("onExit")
Global $aButtons[0][5]
Global $swvButton = 0, $swvAxis = 1, $swvCombo = 2
Func AddButton($bHandle, $lHandle, $sINIname, $swType = $swvButton, $defaultVal = -1)
Local $aTmpIns = [$bHandle,$lHandle,$sINIname,$defaultVal,$swType]
_ArrayTranspose($aTmpIns)
_ArrayAdd($aButtons, $aTmpIns)
EndFunc
#Region ### START Koda GUI section ### Form=
$sAxisTip = "If you're having trouble only moving the stick on one axis, you might try pushing it out all the way and releasing."&@CRLF&"In some cases the return to center will trigger just as well as moving outwards."
$Form1 = GUICreate("Nintendont HID Config Wizard", 720, 433)
$Group1 = GUICtrlCreateGroup("Tiggers and Z Buttons", 310, 40, 400, 100)
;~ $Label19 = GUICtrlCreateLabel("Left Z" , 315, 60, 50, 25, $SS_RIGHT + $SS_CENTERIMAGE)
$Label18 = GUICtrlCreateLabel("Z" , 655, 60, 50, 25, $SS_LEFT + $SS_CENTERIMAGE)
$Label16 = GUICtrlCreateLabel("Left Trig" , 315, 90, 50, 40, $SS_RIGHT + $SS_CENTERIMAGE)
$Label17 = GUICtrlCreateLabel("Right Trig", 655, 90, 50, 40, $SS_LEFT + $SS_CENTERIMAGE)
;~ $bZL = GUICtrlCreateButton("", 370, 60, 50, 25)
$bZ = GUICtrlCreateButton("", 600, 60, 50, 25)
$bLAnalog = GUICtrlCreateButton("", 370, 90, 50, 40)
$bRAnalog = GUICtrlCreateButton("", 600, 90, 50, 40)
;~ GUICtrlSetBkColor($bZL, 0x3399FF)
GUICtrlSetBkColor($bZ , 0x3399FF)
$sMissingZ = "It would seem not every GC controller had a left Z button"
;~ GUICtrlSetTip($bZL , $sMissingZ)
;~ GUICtrlSetTip($Label19, $sMissingZ)
;~ _ArrayAdd($aButtons, [$bZL,$Label19,"ZL_NA"])
AddButton($bZ, $Label18, "Z")
AddButton($bLAnalog, $Label16, "L")
AddButton($bRAnalog, $Label17, "R")
GUICtrlCreateGroup("", -99, -99, 1, 1) ;close group
$Group2 = GUICtrlCreateGroup("Stick", 310, 145, 150, 95)
;~ $Label8 = GUICtrlCreateLabel("Stick", 384, 112, 28, 17)
$Label10 = GUICtrlCreateLabel("Stick V. Axis", 320, 165, 75, 30, $SS_RIGHT + $SS_CENTERIMAGE)
$Label9 = GUICtrlCreateLabel("Stick H. Axis", 320, 200, 75, 30, $SS_RIGHT + $SS_CENTERIMAGE)
$bStickY = GUICtrlCreateButton("", 400, 165, 50, 30)
$bStickX = GUICtrlCreateButton("", 400, 200, 50, 30)
GUICtrlSetTip($Label10, $sAxisTip)
GUICtrlSetTip($Label9 , $sAxisTip)
GUICtrlSetTip($bStickY, $sAxisTip)
GUICtrlSetTip($bStickX, $sAxisTip)
AddButton($bStickY, $Label10, "StickY", $swvAxis)
AddButton($bStickX, $Label9 , "StickX", $swvAxis)
GUICtrlCreateGroup("", -99, -99, 1, 1) ;close group
$Label11 = GUICtrlCreateLabel("Start", 485, 175, 50, 20, $SS_CENTER + $SS_CENTERIMAGE)
$Label20 = GUICtrlCreateLabel("Power", 485, 195, 50, 20, $SS_CENTER + $SS_CENTERIMAGE)
$bStart = GUICtrlCreateButton("", 485, 150, 50, 25)
$bPower = GUICtrlCreateButton("", 485, 215, 50, 25)
GUICtrlSetTip($Label11, "Start")
GUICtrlSetTip($Label20, "Power")
AddButton($bStart, $Label11, "S" )
AddButton($bPower, $Label20, "Power" )
$Group3 = GUICtrlCreateGroup("Buttons", 560, 145, 150, 95)
$Label3 = GUICtrlCreateLabel("Y" , 660, 160, 40, 25, $SS_LEFT + $SS_CENTERIMAGE)
$Label2 = GUICtrlCreateLabel("B" , 570, 185, 40, 20, $SS_CENTER + $SS_CENTERIMAGE)
$Label1 = GUICtrlCreateLabel("A" , 615, 185, 40, 20, $SS_CENTER + $SS_CENTERIMAGE)
$Label4 = GUICtrlCreateLabel("X" , 660, 185, 40, 20, $SS_CENTER + $SS_CENTERIMAGE)
$bY = GUICtrlCreateButton("", 615, 160, 40, 25)
$bB = GUICtrlCreateButton("", 570, 205, 40, 25)
$bA = GUICtrlCreateButton("", 615, 205, 40, 25)
$bX = GUICtrlCreateButton("", 660, 205, 40, 25)
GUICtrlSetTip($bY, "Y")
GUICtrlSetTip($bB, "B")
GUICtrlSetTip($bA, "A")
GUICtrlSetTip($bX, "X")
AddButton($bY, $Label3, "Y")
AddButton($bB, $Label2, "B")
AddButton($bA, $Label1, "A")
AddButton($bX, $Label4, "X")
GUICtrlCreateGroup("", -99, -99, 1, 1) ;close group
$Group4 = GUICtrlCreateGroup("D-Pad", 310, 245, 195, 95)
$Label14 = GUICtrlCreateLabel("D-Pad Left" , 320, 265, 35, 30, $SS_RIGHT + $SS_CENTERIMAGE)
$Label12 = GUICtrlCreateLabel("D-Pad Up" , 460, 265, 35, 30, $SS_LEFT + $SS_CENTERIMAGE)
$Label15 = GUICtrlCreateLabel("D-Pad Down" , 320, 300, 35, 30, $SS_RIGHT + $SS_CENTERIMAGE)
$Label13 = GUICtrlCreateLabel("D-Pad Right", 460, 300, 35, 30, $SS_LEFT + $SS_CENTERIMAGE)
$bLeft = GUICtrlCreateButton("", 360, 265, 45, 30)
$bUp = GUICtrlCreateButton("", 410, 265, 45, 30)
$bDown = GUICtrlCreateButton("", 360, 300, 45, 30)
$bRight = GUICtrlCreateButton("", 410, 300, 45, 30)
GUICtrlSetTip($bLeft , "D-Pad Left" )
GUICtrlSetTip($bUp , "D-Pad Up" )
GUICtrlSetTip($bDown , "D-Pad Down" )
GUICtrlSetTip($bRight, "D-Pad Right")
AddButton($bLeft , $Label14, "Left" )
AddButton($bUp , $Label12, "Up" )
AddButton($bDown , $Label15, "Down" )
AddButton($bRight, $Label13, "Right")
GUICtrlCreateGroup("", -99, -99, 1, 1) ;close group
$Group5 = GUICtrlCreateGroup("C-Stick", 515, 245, 195, 95)
;~ $Label5 = GUICtrlCreateLabel("Stick", 384, 112, 28, 17)
$Label6 = GUICtrlCreateLabel("C-Stick V. Axis", 525, 265, 80, 30, $SS_RIGHT + $SS_CENTERIMAGE)
$Label7 = GUICtrlCreateLabel("C-Stick H. Axis", 525, 300, 80, 30, $SS_RIGHT + $SS_CENTERIMAGE)
$bCStickY = GUICtrlCreateButton("", 610, 265, 80, 30)
$bCStickX = GUICtrlCreateButton("", 610, 300, 80, 30)
GUICtrlSetBkColor($bCStickY, 0xFFFF00)
GUICtrlSetBkColor($bCStickX, 0xFFFF00)
GUICtrlSetTip($Label6 , $sAxisTip)
GUICtrlSetTip($Label7 , $sAxisTip)
GUICtrlSetTip($bCStickY, $sAxisTip)
GUICtrlSetTip($bCStickX, $sAxisTip)
AddButton($bCStickY, $Label6, "CStickY", $swvAxis)
AddButton($bCStickX, $Label7, "CStickX", $swvAxis)
GUICtrlCreateGroup("", -99, -99, 1, 1) ;close group
$cJoy = GUICtrlCreateCombo("" , 10 , 10 , 235, 21, $CBS_DROPDOWN +$CBS_AUTOHSCROLL)
$bJoy = GUICtrlCreateButton("Refresh" , 250, 9 , 50 , 23)
$eRaw = GUICtrlCreateEdit("" , 10 , 42 , 289, 75)
$eIni = GUICtrlCreateEdit("" , 10 , 127, 289, 296)
$iName = GUICtrlCreateInput("Controller Name", 310, 10 , 400, 21)
GUICtrlSetData($eRaw, "")
GUICtrlSetFont($eRaw, 10, 400, 0, "Lucida Console")
GUICtrlSetFont($eIni, 10, 400, 0, "Lucida Console")
GUICtrlSetBkColor($bA, 0x00FF00)
GUICtrlSetBkColor($bB, 0xFF0000)
$Group6 = GUICtrlCreateGroup("Misc", 310, 345, 400, 79)
$bWizzard = GUICtrlCreateButton("Set All", 320, 365, 120, 48)
;~ $bZmod = GUICtrlCreateButton("bZmod" , 632, 392, 51, 25)
$bSave = GUICtrlCreateButton("Save" , 580, 390, 120, 23)
;Combos are vertically auto-sized based on fontsize, in this case they are 21px high. Thier surrounding are sized to match
$cDPAD = GUICtrlCreateCombo("" , 450, 366, 118, 21, $CBS_DROPDOWN + $CBS_AUTOHSCROLL)
$cPollType = GUICtrlCreateCombo("" , 450, 391, 118, 21, $CBS_DROPDOWN + $CBS_AUTOHSCROLL)
$cTrigType = GUICtrlCreateCombo("" , 580, 366, 118, 21, $CBS_DROPDOWN + $CBS_AUTOHSCROLL)
GUICtrlSetFont($bWizzard, 18, 400, 0, "MS Sans Serif")
GUICtrlSetData($cDPAD , "DPAD = 0|DPAD = 1", "DPAD = 1" )
GUICtrlSetData($cPollType, "PollType = 0|PollType = 1", "PollType = 1" )
GUICtrlSetData($cTrigType, "DigitalLR = 0|DigitalLR = 1", "DigitalLR = 1")
GUICtrlSetTip($bWizzard , "Begin a sequence to set each button." )
GUICtrlSetTip($cDPAD , "1 if it uses a full byte, 0 if it uses only 4 bits")
GUICtrlSetTip($cPollType, "The only known case of this needing to be 0 is the PS3 Controller, or my GC style switch one it seems.")
GUICtrlSetTip($cTrigType, "Set this to 1 if your trigger can't tell how far you've pulled them. BTW this program doesn't support 0, so you'd need to do some manual tweaks.")
AddButton($cDPAD , $Group6, "DPAD", $swvCombo, 1)
AddButton($cPollType, $Group6, "Polltype", $swvCombo, 1)
AddButton($cTrigType, $Group6, "DigitalLR", $swvCombo, 1)
GUICtrlCreateGroup("", -99, -99, 1, 1) ;close group
#EndRegion ### END Koda GUI section ###
For $i = 0 to UBound($aButtons) - 1
$temp = $aButtons[$i][3]
ConsoleWrite("> "&$aButtons[$i][2]&" = "&$temp&" "&($temp <> -1)&@CRLF)
Next
Global $VID, $PID, $JoyName, $WaitForButton = 0
Global $hWin, $hEdit1, $hEdit2, $hCombo
Global $IniPath = @ScriptDir&"\controllers"
DirCreate($IniPath)
ReloadJoyList()
UpdateIni()
HotKeySet("{esc}", "ExitProgram")
GUISetState(@SW_SHOW)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $bJoy
ProcessClose("hidTrace.exe")
ProcessClose("hidTrace.exe")
sleep(200)
ReloadJoyList()
; runs LoadJoy after
Case $cJoy
LoadJoy(GUICtrlRead($cJoy))
Case $bWizzard
dowizzard()
Case $iName
$JoyName = GUICtrlRead($iName)
UpdateIni()
Case $bSave
SaveIni()
EndSwitch
For $iButton = 0 to UBound($aButtons) - 1
If $nMsg = $aButtons[$iButton][0] Then
If SetButton($iButton) Then
UpdateIni()
EndIf
EndIf
Next
If StringTrimLeft(ControlGetText($hWin, "", $hEdit2), 10) <> GUICtrlRead($eRaw) Then
GUICtrlSetData($eRaw, StringTrimLeft(ControlGetText($hWin, "", $hEdit2), 10))
EndIf
WEnd
Func SetButton($iButton, $aBaseline = "")
ControlFocus($Form1, "", $iName)
Local $i, $timer = TimerInit()
If $aButtons[$iButton][4] = $swvCombo Then
If $aBaseline = "" or Not IsArray($aBaseline) Then
Local $aTmp[1] = [GUICtrlRead($aButtons[$iButton][0])]
$aBaseline = $aTmp
EndIf
Else
If $aBaseline = "" or Not IsArray($aBaseline) Then
;~ MsgBox(0, "Setup Wizzard", "Release all buttons / sticks and click ok to continue")
$aBaseline = StringRegExp(StringTrimLeft(ControlGetText($hWin, "", $hEdit2), 10), " ([0-9a-fA-F]{2})(?= )", 3)
If Not IsArray($aBaseline) Then
SplashOff()
MsgBox(0, "Error", "Error creating baseline! Make sure controller is on and plugged in"&@CRLF&"E:1")
Return -1
EndIf
EndIf
EndIf
Local $aCurrentState
;~ _ArrayDisplay($aBaseline)
If $aButtons[$iButton][4] <> $swvCombo Then
SplashTextOn("", "Press "&GUICtrlRead($aButtons[$iButton][1])&" to set, SPACE to skip, or ESC to cancel", 200, 150)
EndIf
$WaitForButton = 1
While $WaitForButton
;~ If TimerDiff($timer) > 5000 Then ExitLoop
If StringTrimLeft(ControlGetText($hWin, "", $hEdit2), 10) <> GUICtrlRead($eRaw) Then
GUICtrlSetData($eRaw, StringTrimLeft(ControlGetText($hWin, "", $hEdit2), 10))
EndIf
If $aButtons[$iButton][4] = $swvCombo Then
Local $aTmp[1] = [GUICtrlRead($aButtons[$iButton][0])]
$aCurrentState = $aTmp
Else
$aCurrentState = StringRegExp(StringTrimLeft(ControlGetText($hWin, "", $hEdit2), 10), " ([0-9a-fA-F]{2})(?= )", 3)
EndIf
If Not IsArray($aCurrentState) Then
SplashOff()
MsgBox(0, "Error", "Error creating baseline! Make sure controller is on and plugged in"&@CRLF&"E:1")
Return -1
EndIf
For $i = 0 to UBound($aBaseline) - 1
;$temp will store the difference of the two hex bytes being examined
If $aButtons[$iButton][4] = $swvCombo Then
$temp = True
Else
$temp = Dec($aCurrentState[$i])-Dec($aBaseline[$i])
EndIf
;seperate handleing for combos and for sticks. Make sure the difference is more than an amount, to help prevent accidental buttons
Switch $aButtons[$iButton][4]
Case $swvButton
If $temp > 0 Then
ConsoleWrite("2> Change at index "&$i&" from "&$aBaseline[$i]&" to "&$aCurrentState[$i]&@CRLF)
ConsoleWrite($aButtons[$iButton][2]&"="&$i&","&hex($temp, 2) &@CRLF)
$WaitForButton = 0
SplashOff()
GUICtrlSetData($aButtons[$iButton][0], $i&","&hex($temp, 2))
$aButtons[$iButton][3] = $i&","&hex($temp, 2)
Return 1
ElseIf $temp < 0 Then ; Special handleing: IF the difference is negitive, then chances are you need the absolute
ConsoleWrite("3> Change at index "&$i&" from "&$aBaseline[$i]&" to "&$aCurrentState[$i]&@CRLF)
ConsoleWrite($aButtons[$iButton][2]&"="&$i&","& $aCurrentState[$i] &@CRLF)
$WaitForButton = 0
SplashOff()
GUICtrlSetData($aButtons[$iButton][0], $i&","&$aCurrentState[$i])
$aButtons[$iButton][3] = $i&","&$aCurrentState[$i]
Return 1
EndIf
Case $swvAxis
If Abs($temp) > 20 Then
ConsoleWrite("1> Change at index "&$i&" from "&$aBaseline[$i]&" to "&$aCurrentState[$i]&@CRLF)
ConsoleWrite($aButtons[$iButton][2]&"="&$i &@CRLF)
$WaitForButton = 0
SplashOff()
GUICtrlSetData($aButtons[$iButton][0], $i)
$aButtons[$iButton][3] = $i
Return 1
EndIf
Case $swvCombo
If $temp Then
ConsoleWrite("4> Change at index "&$i&" to "&$aCurrentState[$i]&@CRLF)
$WaitForButton = 0
SplashOff()
If StringInStr(GUICtrlRead($aButtons[$iButton][0]),"1") Then
$aButtons[$iButton][3] = 1
Else
$aButtons[$iButton][3] = 0
EndIf
Return 1
EndIf
EndSwitch
Next
WEnd
$WaitForButton = 0
SplashOff()
Return -1
EndFunc
Func WaitForRelease($aBaseline)
Local $aCurrentState, $i, $timer = TimerInit()
sleep(200)
while sleep(100)
$aCurrentState = StringRegExp(StringTrimLeft(ControlGetText($hWin, "", $hEdit2), 10), " ([0-9a-fA-F]{2})(?= )", 3)
If Not IsArray($aCurrentState) Then
SplashOff()
MsgBox(0, "Error", "Error getting controller state! Make sure controller is on and plugged in")
Return -1
EndIf
For $i = 0 to UBound($aBaseline)-1
;$temp will store the difference of the two hex bytes being examined
If $aCurrentState[$i] <> $aBaseline[$i] Then ExitLoop
If $i = UBound($aBaseline)-1 Then Return 1
Next
If TimerDiff($timer) > 5000 Then ExitLoop
WEnd
return 0
EndFunc
Func UpdateIni()
Local $i, $s = "", $temp
$s = "["&$JoyName&"]"&@CRLF&"VID="&$VID&@CRLF&"PID="&$PID&@CRLF
For $i = 0 to UBound($aButtons) - 1
$temp = $aButtons[$i][3]
ConsoleWrite("> "&$aButtons[$i][2]&" = "&$temp&" "&($temp <> -1)&@CRLF)
If $temp <> -1 Then $s &= $aButtons[$i][2]&"="&$temp&@CRLF
Next
$s &= "MultiIn=0"&@CRLF
$s &= "LAnalog=0"&@CRLF
$s &= "RAnalog=0"&@CRLF
GUICtrlSetData($eIni, $s)
EndFunc
Func SaveIni()
Local $temp = $IniPath&"\"&$VID&"_"&$PID&".ini"
If Not FileExists($temp) or MsgBox(4, "File exists!",$VID&"_"&$PID&".ini already exists in the folder"&@CRLF&$IniPath&@CRLF&"Do you want to overwrite it?") = 6 Then
FileRecycle($temp)
FileWrite($temp, GUICtrlRead($eIni))
EndIf
; clear the gui messages in case the user hit gui buttons while the msgbox was up
While GUIGetMsg() <> 0
WEnd
EndFunc
Func LoadIni()
Local $temp, $iButton, $path = $IniPath&"\"&$VID&"_"&$PID&".ini"
ConsoleWrite("+ "&$IniPath&"\"&$VID&"_"&$PID&".ini"&@CRLF)
If Not FileExists($path) Then return 0
$temp = IniReadSectionNames($path)
If not IsArray($temp) Then return -1
$JoyName = $temp[1]
ConsoleWrite("Loaded joystick named: "&$JoyName&@CRLF)
For $iButton = 0 to UBound($aButtons) - 1
$temp = IniRead($path, $JoyName, $aButtons[$iButton][2], -1)
$aButtons[$iButton][3] = $temp
If $temp > -1 Then GUICtrlSetData($aButtons[$iButton][0], $temp)
Next
; clear the gui messages in case the user hit gui buttons while the msgbox was up
While GUIGetMsg() <> 0
WEnd
UpdateIni()
EndFunc
Func dowizzard()
MsgBox(0, "Setup Wizzard", "Release all buttons / sticks and click ok to continue")
Local $i, $aBaseline = StringRegExp(StringTrimLeft(ControlGetText($hWin, "", $hEdit2), 10), " ([0-9a-fA-F]{2})(?= )", 3)
For $iButton = 0 to UBound($aButtons) - 1
If $aButtons[$iButton][4] <> $swvCombo Then
If SetButton($iButton) = -1 Then ExitLoop
If WaitForRelease($aBaseline) <> 1 Then
SplashOff()
$WaitForButton = 0
MsgBox(0, "Error", "Button jammed / not released after setting "&GUICtrlRead($aButtons[$iButton][1])&"!"&@CRLF&"Check controller and try again.")
Return -1
EndIf
EndIf
Next
$WaitForButton = 0
UpdateIni()
EndFunc
Func ExitProgram()
If $WaitForButton = 1 Then
$WaitForButton = 0
Else
Exit
EndIf
EndFunc
Func ReloadJoyList()
Run("hidTrace.exe", "", @SW_HIDE)
$hWin = WinWait("HID Trace - (c) Atomix Productions 2009", "", 2)
$hCombo = ControlGetHandle($hWin, "", "[CLASS:ComboBox; INSTANCE:1]")
$hEdit1 = ControlGetHandle($hWin, "", "[CLASS:Edit; INSTANCE:1]")
$hEdit2 = ControlGetHandle($hWin, "", "[CLASS:Edit; INSTANCE:2]")
WinActivate($Form1)
if Not $hCombo Then Exit MsgBox(0, "Error", "Could not run HidTrace (no window found!)")
$joyList = StringRegExpReplace(_GUICtrlComboBox_GetList($hCombo), "(\d{1,5}e? \/ \d{1,5}e?\|?)", "")
ConsoleWrite('"'&$joyList&'"'&@CRLF)
If $joyList = "" Then
;~ MsgBox(0, "Error", "No controllers found! Check controllers and re-run this program")
$joyList = "None found - Hit Refresh"
EndIf
If StringInStr($joyList, GUICtrlRead($cJoy)) Then
$temp = GUICtrlRead($cJoy)
GUICtrlSetData($cJoy, "")
GUICtrlSetData($cJoy, $joyList, $temp)
Else
GUICtrlSetData($cJoy, "")
Local $temp = StringSplit($joyList, "|")
GUICtrlSetData($cJoy, $joyList, $temp[1])
EndIf
LoadJoy(GUICtrlRead($cJoy))
UpdateIni()
EndFunc
func LoadJoy($sName)
ConsoleWrite("LoadJoy("&$sName&")"&@CRLF)
; assign default values
$VID = 0
$PID = 0
For $iButton = 0 to UBound($aButtons) - 1
If $aButtons[$iButton][4] <> $swvCombo Then
$aButtons[$iButton][3] = -1
Else
If StringInStr(GUICtrlRead($aButtons[$iButton][0]),"1") Then
$aButtons[$iButton][3] = 1
Else
$aButtons[$iButton][3] = 0
EndIf
EndIf
Next
$JoyName = $sName
ControlCommand($hWin, "", $hCombo, "SelectString", $sName)
$a = StringRegExp(ControlGetText($hWin, "", $hEdit1), "VID=([0-9a-fA-F)]{4})\|PID=([0-9a-fA-F)]{4})", 3)
If @error Then return -1
$VID = $a[0]
$PID = $a[1]
LoadIni()
;attempt name lookup from ID's
If $usbIDs <> "" Then
Local $temp = StringRegExp($usbIDs, $VID&" [^\r\n]*[\r\n]*\s*"&$PID&"\s\s([^\r\n]*)", 3)
If UBound($temp) = 1 Then
$JoyName = $temp[0]
EndIf
EndIf
GUICtrlSetData($iName, $JoyName)
EndFunc
Func onExit()
ProcessClose("hidTrace.exe")
EndFunc