IAMK Posted November 7, 2018 Share Posted November 7, 2018 (edited) I currently have the following script: expandcollapse popupLocal $8buttonsX[9] = ["NULL", 400, 770, 1130, 1530, 400, 770, 1130, 1530] Local $8buttonsY[9] = ["NULL", 310, 310, 310, 310, 670, 670, 670, 670] Local $9buttonsX[10] = ["NULL", 500, 960, 1420, 500, 960, 1420, 500, 960, 1420] Local $9buttonsY[10] = ["NULL", 220, 220, 220, 480, 480, 480, 760, 760, 760] Local $10buttonsX[11] = ["NULL", 420, 790, 1150, 1520, 420, 790, 1150, 1520, 790, 1150] Local $10buttonsY[11] = ["NULL", 240, 240, 240, 240, 500, 500, 500, 500, 770, 770] Local $11buttonsX[12] = ["NULL", 420, 790, 1150, 1520, 420, 790, 1150, 1520, 600, 960, 1320] Local $11buttonsY[12] = ["NULL", 240, 240, 240, 240, 500, 500, 500, 500, 770, 770, 770] Local $12buttonsX[13] = ["NULL", 420, 790, 1150, 1520, 420, 790, 1150, 1520, 420, 790, 1150, 1520] Local $12buttonsY[13] = ["NULL", 240, 240, 240, 240, 500, 500, 500, 500, 770, 770, 770, 770] Func Select8buttons($buttonList, $buttonNum, ByRef $buttonName) $buttonName = $buttonList[$buttonNum] ;Update the name of the button to the button being pressed. MouseClick("Primary", $8buttonsX[$buttonNum], $8buttonsY[$buttonNum], 1, 0) EndFunc Func Select9buttons($buttonList, $buttonNum, ByRef $buttonName) $buttonName = $buttonList[$buttonNum] ;Update the name of the button to the button being pressed. MouseClick("Primary", $9buttonsX[$buttonNum], $9buttonsY[$buttonNum], 1, 0) EndFunc Func Select10buttons($buttonList, $buttonNum, ByRef $buttonName) $buttonName = $buttonList[$buttonNum] ;Update the name of the button to the button being pressed. MouseClick("Primary", $10buttonsX[$buttonNum], $10buttonsY[$buttonNum], 1, 0) EndFunc Func Select11buttons($buttonList, $buttonNum, ByRef $buttonName) $buttonName = $buttonList[$buttonNum] ;Update the name of the button to the button being pressed. MouseClick("Primary", $11buttonsX[$buttonNum], $11buttonsY[$buttonNum], 1, 0) EndFunc Func Select12buttons($buttonList, $buttonNum, ByRef $buttonName) $buttonName = $buttonList[$buttonNum] ;Update the name of the button to the button being pressed. MouseClick("Primary", $12buttonsX[$buttonNum], $12buttonsY[$buttonNum], 1, 0) EndFunc Func SelectNextbutton($buttonList, $buttonNum, ByRef $buttonName) $buttonNum = $buttonNum + 1 ;Increment $buttonNum If($buttonNum > UBound($buttonList)) Then ;If $buttonNum is bigger than the amount of buttons in chooser. $buttonNum = 1 ;Reset $buttonNum to 1 (first button in chooser). EndIf Call("Select" & UBound($buttonList) - 1 & "buttons", $buttonList, $buttonNum, $buttonName) ;Get the next button and call one of the above functions. While(PixelGetColor(10, 10) == 9110) ;Looks for page to change colour. Sleep(200) WEnd EndFunc Many of the functions can be removed by simply doing something like the following: Local $8buttonsX[9] = ["NULL", 400, 770, 1130, 1530, 400, 770, 1130, 1530] Local $8buttonsY[9] = ["NULL", 310, 310, 310, 310, 670, 670, 670, 670] Local $9buttonsX[10] = ["NULL", 500, 960, 1420, 500, 960, 1420, 500, 960, 1420] Local $9buttonsY[10] = ["NULL", 220, 220, 220, 480, 480, 480, 760, 760, 760] Local $10buttonsX[11] = ["NULL", 420, 790, 1150, 1520, 420, 790, 1150, 1520, 790, 1150] Local $10buttonsY[11] = ["NULL", 240, 240, 240, 240, 500, 500, 500, 500, 770, 770] Local $11buttonsX[12] = ["NULL", 420, 790, 1150, 1520, 420, 790, 1150, 1520, 600, 960, 1320] Local $11buttonsY[12] = ["NULL", 240, 240, 240, 240, 500, 500, 500, 500, 770, 770, 770] Local $12buttonsX[13] = ["NULL", 420, 790, 1150, 1520, 420, 790, 1150, 1520, 420, 790, 1150, 1520] Local $12buttonsY[13] = ["NULL", 240, 240, 240, 240, 500, 500, 500, 500, 770, 770, 770, 770] Func SelectNextbutton($buttonList, $buttonNum, ByRef $buttonName) $buttonNum = $buttonNum + 1 ;Increment $buttonNum If($buttonNum > UBound($buttonList)) Then ;If $buttonNum is bigger than the amount of buttons in chooser. $buttonNum = 1 ;Reset $buttonNum to 1 (first button in chooser). EndIf $buttonName = $buttonList[$buttonNum] ;Update the name of the button to the button being pressed. MouseClick("Primary", Execute("$" & String(UBound($buttonList) - 1) & "buttonsX[$buttonNum]"), Execute("$" & String(UBound($buttonList) - 1) & "buttonsY[$buttonNum]"), 1, 0) While(PixelGetColor(10, 10) == 9110) ;Looks for page to change colour. Sleep(200) WEnd EndFunc Question1: In an environment where non-programmers will need to update/use parts of my scripts in the future, how should I be implementing my code? a- Hardcoded, English code with A LOT of text (example 1). b- Dynamic code which reduces the amount of text/duplication, but is much more complex (example 2). Question2: I considered cutting down the button arrays, but I wasn't sure how to do it nicely. Is there a way to do it? I thought of using modulus/multiplication to figure out which x, y positions to click. E.g. 11 buttons looks like: If It was 12 buttons, I could modulus the x and y values and only store 4 unique values in the x array and 3 in the y array (refer to post #3). With 11 buttons, modulus works for the first 2 rows, but then I couldn't handle (that I know of) the 3rd row without having individual logic to offset x by some number. Thank you in advance. Edited November 7, 2018 by IAMK Link to comment Share on other sites More sharing options...
caramen Posted November 7, 2018 Share Posted November 7, 2018 6 hours ago, IAMK said: Question1: In an environment where non-programmers will be using my scripts, how should I be implementing my code? I whould recommand you to dont allow user to interact with the code anyway. So if they need to update anything you make them able to do that with a [Button] and you record the changed cvalue somewhere. So the improvement/update will be done automated way by your coding. 6 hours ago, IAMK said: Question2: I considered cutting down the button arrays, but I wasn't sure how to do it nicely. Is there a way to do it? Dont forget we'nt in your mind. It totaly depend of what you trying to do. I suggest you to just go to the easyest way to do what you want. Anyway. Probably if you explain more the goal of question 2 we can elaborate somthing more reliable for your case. My video tutorials : ( In construction ) || My Discord : https://discord.gg/S9AnwHw How to Ask Help || UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote Spoiler Water's UDFs:Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsPowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & SupportExcel - Example Scripts - WikiWord - Wiki Tutorials:ADO - Wiki Link to comment Share on other sites More sharing options...
IAMK Posted November 7, 2018 Author Share Posted November 7, 2018 @caramen For question 1, I meant that in the future, if the positions of the buttons or the number of buttons possible changes, they will need to update the script. For question 2, the code for 12 buttons would be: Local $12buttonsX[13] = ["NULL", 420, 790, 1150, 1520] Local $12buttonsY[13] = ["NULL", 240, 500, 770] MouseClick("Primary", Execute("$" & String(UBound($buttonList) - 1) & "buttonsX[" & String(Mod($buttonNum, 4) + 1) & "]"), Execute("$" & String(UBound($buttonList) - 1) & "buttonsY[" & String(Floor($buttonNum / 3) + 1) & "]"), 1, 0) Mod to find the x and divide to find the y. How would you implement the same, but for 11buttons? Link to comment Share on other sites More sharing options...
caramen Posted November 7, 2018 Share Posted November 7, 2018 For question 1 i copy past you one of my existing code so you can read, understand, adapt to your needs. The logic is what i said : Grade the coordinates as you want record that in a file. And call it later. With possibility to come back at defaut stat. Case $Buttom4 $CalibrageYesNo = MsgBox ($MB_YESNO , "Calibrage" , "Voulez-vous calibrer ?") If $CalibrageYesNo = "6" Then MsgBox (0 , "Explanation what to do" , "After pressing OK Press F8 to record the mouse position") Do Sleep (100) Until _IsPressed (77) ;F8 $Coordonnees = MouseGetPos () $iRows = UBound ($Coordonnees) If $iRows = 2 Then $Xc = $Coordonnees [0] $Yc = $Coordonnees [1] $Xf = $Coordonnees [0] $Yf = $Coordonnees [1] If ProcessExists ("Chrome.exe") Then $IniXc = IniWrite (""&$IniLocation , "Coordonnées" , "Xc" , ""&$Xc ) $IniYc = IniWrite (""&$IniLocation , "Coordonnées" , "Yc" , ""&$Yc ) ElseIf ProcessExists ("FireFox.exe") Then $IniXf = IniWrite (""&$IniLocation , "Coordonnées" , "Xf" , ""&$Xf ) $IniYf = IniWrite (""&$IniLocation , "Coordonnées" , "Yf" , ""&$Yf ) EndIf EndIf MsgBox (0 , "Graduate" , "Grade over.") EndIf My video tutorials : ( In construction ) || My Discord : https://discord.gg/S9AnwHw How to Ask Help || UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote Spoiler Water's UDFs:Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsPowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & SupportExcel - Example Scripts - WikiWord - Wiki Tutorials:ADO - Wiki Link to comment Share on other sites More sharing options...
caramen Posted November 7, 2018 Share Posted November 7, 2018 (edited) Question 2: Guess there is a looot of way to do it. The first thing i thought is ... Just add estimated coordinate amount to Add to the first coordinate : First button at x=0 , y=0 If second button is at x2=0 - y2=50 I whould just do : y2 = Y + Y2 / 2 Btw i whould prefer a recorded coordinate that will be constant in stead of a calculated coordinate that can fail. Maybe you can record all defaut coordinate and lunch a grade function after any change. that is what i whould do. If the position always change. I whould do a grade function at each script start. This little improvement whould make your scipt avaiable for user even in case of software update. In case of MAJOR changes just rewrite your code. You can't anticipate everything unfortunatly Edited November 7, 2018 by caramen My video tutorials : ( In construction ) || My Discord : https://discord.gg/S9AnwHw How to Ask Help || UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote Spoiler Water's UDFs:Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsPowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & SupportExcel - Example Scripts - WikiWord - Wiki Tutorials:ADO - Wiki Link to comment Share on other sites More sharing options...
IAMK Posted November 8, 2018 Author Share Posted November 8, 2018 (edited) @caramen Thanks, I will look into how to adjust your implementation of 1. Note: This is a script which is included by all other scripts and never run by itself. In my case, it's not so much the positions of the buttons which change with updates, but rather how many buttons there are (handled by the array). For #2, that is what I had in mind too. maybe something like (assume normal positions are 0, 100, 200, 300 and half-positions are 50, 150, 250 to make things simpler): Local $offset = 0 If(UBound($buttonList) = 11 And ($buttonNum = 9 Or $buttonNum = 10 Or $buttonNum = 11)) Then $offset = 50 ElseIf(UBound($buttonList) = 10 And ($buttonNum = 9 Or $buttonNum = 10)) Then $offset = 100 EndIf Local $extra = 0 If(UBound($buttonList) = 10 Or UBound($buttonList) = 11) Then $extra = $buttonNum - 9 ;10buttons=2extra, 11buttons=3extra. EndIf MouseClick("Primary", Execute("$" & String(UBound($buttonList) - 1) & "buttonsX[" & String(Mod($buttonNum, 4) + 1) & "]") + ($offset + (100 * $extra)), Execute("$" & String(UBound($buttonList) - 1) & "buttonsY[" & String(Floor($buttonNum / 3) + 1) & "]"), 1, 0) It requires 2 variables and 3 ifstatements prior to the MouseClick(), which is also expanded by "+ ($offset + (100 * $extra))". Edited November 8, 2018 by IAMK Fixed Syntax 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