-
Posts
912 -
Joined
-
Days Won
1
Reputation Activity
-
Deye got a reaction from SOLVE-SMART in Accurate names for the autoit functions
Are there any ways as to how can I distinguish the real names from the ones that arent valid on progress
Func _ChangeImageColors($sInputImagePath, $sOutputImagePath, $aColorMap) _GDIPlus_Startup() Local $hImage = _GDIPlus_ImageLoadFromFile($sInputImagePath) If @error Then Return False Local $hGraphics = _GDIPlus_GraphicsCreateFromImage($hImage) Local $iWidth = _GDIPlus_ImageGetWidth($hImage) Local $iHeight = _GDIPlus_ImageGetHeight($hImage) For $i = 0 To $iWidth - 1 For $j = 0 To $iHeight - 1 Local $iPixelColor = _GDIPlus_BitmapGetPixel($hImage, $i, $j) Local $newColor = $aColorMap[0] _GDIPlus_GraphicsDrawRectangle($hGraphics, $i, $j, 1, 1, $newColor) Next Next _GDIPlus_ImageSaveToFile($hImage, $sOutputImagePath) _GDIPlus_GraphicsDispose($hGraphics) _GDIPlus_ImageDispose($hImage) _GDIPlus_Shutdown() Return True EndFunc ;==>_ChangeImageColors
-
Deye reacted to Nine in follow the typewriter effect
I see. Well good luck with this project. Post the code when you are done in the example section.
ps : I recently work on this UDF. It may be of interest for you.
-
Deye reacted to jchd in Need help with the _arraysearch() on a 2D array - (Moved)
Post edited: I did see the * -1 part (and didn't expect it), just the > 0 caught my (olding) eyes.
-
Deye got a reaction from AspirinJunkie in Fastest Way to Delete Empty Records in 1d Array
apologies, but in order to try your hand at this function fairly , you must pass the correct arguments, especially the delimiter being used.
like so,
_Deye_ArrayDelEmptyRows($aArray, Chr(34)) or _Deye_ArrayDelEmptyRows($aArray, '"')
-
Deye got a reaction from web2win in AutoIt Snippets
Implode or explode your GUI from anywhere on your screen: holding the mouse pressed on the GUI while dragging will resize the GUI preserving it's dimension
#include <GuiconstantsEx.au3> #include <WinAPISys.au3> #include <WinAPIGdi.au3> #include <Misc.au3> Opt("GUIResizeMode", 904) $hDLL = DllOpen("user32.dll") OnAutoItExitRegister("On_Exit") Global $iWidth = 380, $iHeight = 180 Global $hGUI = GUICreate("X", $iWidth, $iHeight, -1, -1) GUISetBkColor(0X5c6e8c, $hGUI) $iWidth = _WinAPI_GetClientWidth($hGUI) $iHeight = _WinAPI_GetClientHeight($hGUI) $ButtonWidth = 40 $ButtonHeight = 20 $idnew = GUICtrlCreateButton("Change Dimension", ($iWidth / 2) - (3 * $ButtonWidth / 2), ($iHeight / 2) - (4 * $ButtonHeight / 2), 3 * $ButtonWidth, $ButtonHeight) $idCenter = GUICtrlCreateButton("x", ($iWidth / 2) - ($ButtonWidth / 2), ($iHeight / 2) - ($ButtonHeight / 2), $ButtonWidth, $ButtonHeight) GUICtrlSetFont($idCenter, 10, 200) Global $PM = _WinAPI_MonitorFromWindow($hGUI) DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $hGUI, "int", 500, "long", 0x00040010) GUISetState() $aGPos = WinGetPos($hGUI) $iWidth = $aGPos[2] $iHeight = $aGPos[3] While 1 Switch GUIGetMsg() Case $GUI_EVENT_close Exit Case $idnew $iWidth = Random(150, 550, 1) $iHeight = Random(150, 550, 1) _NewDimension($iWidth, $iHeight) Case $idCenter _CenterToScreen() Case $GUI_EVENT_PRIMARYDOWN OnDrag() EndSwitch WEnd Func OnDrag() Local $aPos, $iRoll, $X, $Y, $width, $height, $PH, $PW = 0, $aCurInfo = GUIGetCursorInfo($hGUI) If $aCurInfo[4] <> 0 Then Return ; Mouse is over a control Local $aGPos = WinGetPos($hGUI) Local $aMPos = MouseGetPos() Local $MON = _WinAPI_MonitorFromWindow($hGUI) Local $aMax = MonitorGetRect($MON) If $PM <> $MON Then $PM = $MON Return _CenterToScreen(1) EndIf If _SnapToScreen($aGPos, $aMax) Then Return WinMove($hGUI, "", $aGPos[0], $aGPos[1], $aGPos[2], $aGPos[3]) $width = $aGPos[2] $height = $aGPos[3] While _IsPressed("01", $hDLL) $aPos = MouseGetPos() $iRoll = (($aMPos[1] - $aPos[1]) - ($aMPos[0] - $aPos[0])) * 100 / 50 $height = ($aGPos[3] / $aGPos[2]) * ($aGPos[2] + $iRoll) If $height < $iHeight Then ExitLoop If $height >= $aMax[3] Then Do $iRoll -= 1 $height = Round(($aGPos[3] / $aGPos[2]) * ($aGPos[2] + $iRoll)) Until $height <= $aMax[3] EndIf $width = ($aGPos[2] / $aGPos[3]) * $height If $width >= ($aMax[2] - $aMax[0]) Then Do $iRoll -= 1 $height = Round(($aGPos[3] / $aGPos[2]) * ($aGPos[2] + $iRoll)) $width = ($aGPos[2] / $aGPos[3]) * $height Until $width <= ($aMax[2] - $aMax[0]) EndIf ;Store as Previous Width & Height $PW = $width $PH = $height $X = Round((($aGPos[2] / 2) + $aGPos[0]) - ($width / 2)) $Y = Round((($aGPos[3] / 2) + $aGPos[1]) - ($height / 2)) If $X <= $aMax[0] Then $X = $aMax[0] ElseIf ($X + $width) >= $aMax[2] Then $X = ($aMax[2] - $width) EndIf If $Y <= $aMax[1] Then $Y = $aMax[1] ElseIf ($Y + $height) >= $aMax[3] Then $Y = ($aMax[3] - $height) EndIf WinMove($hGUI, "", $X, $Y, $width, $height) Sleep(20) WEnd If $height < $iHeight And $PW <> 0 Then $tRect = _WinAPI_GetWindowRect($hGUI) Return WinMove($hGUI, "", (($PW / 2) + DllStructGetData($tRect, "Left")) - ($iWidth / 2), Ceiling(($PH / 2) + DllStructGetData($tRect, "Top")) - ($iHeight / 2), $iWidth, $iHeight) EndIf EndFunc ;==>OnDrag Func _SnapToScreen(ByRef $aGPos, ByRef $aMax) ; Snap the gui back to its full view when moved off screen Local $Move = False If $aGPos[0] < $aMax[0] Then $aGPos[0] = $aMax[0] $Move = True ElseIf ($aGPos[0] + $aGPos[2]) > $aMax[2] Then $aGPos[0] = ($aMax[2] - $aGPos[2]) $Move = True EndIf If $aGPos[1] < $aMax[1] Then $aGPos[1] = $aMax[1] $Move = True ElseIf ($aGPos[1] + $aGPos[3]) > $aMax[3] Then $aGPos[1] = ($aMax[3] - $aGPos[3]) $Move = True EndIf If $Move Then Return True EndFunc ;==>_SnapToScreen Func _NewDimension($width, $height) Local $aPos = WinGetPos($hGUI) Return WinMove($hGUI, "", ($aPos[2] / 2) + $aPos[0] - ($width / 2), ($aPos[3] / 2) + $aPos[1] - ($height / 2), $width, $height) EndFunc ;==>_NewDimension Func _CenterToScreen($Move =False) Local $aMax = MonitorGetRect(_WinAPI_MonitorFromWindow($hGUI)) ; Center & Resize the gui dimension if off screen Local $aGPos = WinGetPos($hGUI) Local $check = $aGPos[2] If $aGPos[3] > ($aMax[3] - $aMax[1]) Then $aGPos[2] = Round(($aGPos[2] / $aGPos[3]) * ($aMax[3] - $aMax[1])) ;New Width $aGPos[3] = $aMax[3] - $aMax[1] ;New Height EndIf If $aGPos[2] > ($aMax[2] - $aMax[0]) Then $aGPos[3] = Round(($aGPos[3] / $aGPos[2]) * ($aMax[2] - $aMax[0])) ;New Height $aGPos[2] = $aMax[2] - $aMax[0] ;New Width EndIf If $Move and $check = $aGPos[2] then Return Return WinMove($hGUI, "", (($aMax[2] + $aMax[0]) / 2) - ($aGPos[2] / 2), (($aMax[1] + $aMax[3]) / 2) - ($aGPos[3] / 2), $aGPos[2], $aGPos[3]) EndFunc ;==>_CenterToScreen Func MonitorGetRect($hMonitor) Local $aData = _WinAPI_GetMonitorInfo($hMonitor) Local $s = DllStructGetData($aData[1], 1) & ',' & DllStructGetData($aData[1], 2) & ',' & DllStructGetData($aData[1], 3) & ',' & DllStructGetData($aData[1], 4) Local $a = StringSplit($s, ',', 2) Return $a EndFunc ;==>MonitorGetRect Func On_Exit() DllClose($hDLL) EndFunc ;==>On_Exit
-
-
-
Deye reacted to Skeletor in ImageTOGreyscale
I took some inspiration from this post. They used a screen capture, I modified the script to rather open an image.
Try this:
#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w 7 #include <GDIPlus.au3> Example() Func Example() _GDIPlus_Startup() Local $sInputFile = "image.jpg" Local $sOutputFile = "image_gray.jpg" Local $hImage = _GDIPlus_ImageLoadFromFile($sInputFile) If Not $hImage Then ConsoleWriteError("Failed to load image: " & $sInputFile & @CRLF) Return False EndIf Local Const $iWidth = _GDIPlus_ImageGetWidth($hImage) Local Const $iHeight = _GDIPlus_ImageGetHeight($hImage) Local $hIA = _GDIPlus_ImageAttributesCreate() Local $tColorMatrix = _GDIPlus_ColorMatrixCreateGrayScale() _GDIPlus_ImageAttributesSetColorMatrix($hIA, 0, True, $tColorMatrix) Local $hBitmap = _GDIPlus_BitmapCreateFromScan0($iWidth, $iHeight) Local $hGraphics = _GDIPlus_ImageGetGraphicsContext($hBitmap) _GDIPlus_GraphicsDrawImageRect($hGraphics, $hImage, 0, 0, $iWidth, $iHeight) _GDIPlus_GraphicsDispose($hGraphics) $hGraphics = _GDIPlus_ImageGetGraphicsContext($hBitmap) _GDIPlus_GraphicsDrawImageRectRect($hGraphics, $hBitmap, 0, 0, $iWidth, $iHeight, 0, 0, $iWidth, $iHeight, $hIA) _GDIPlus_ImageSaveToFile($hBitmap, $sOutputFile) _GDIPlus_ImageAttributesDispose($hIA) _GDIPlus_GraphicsDispose($hGraphics) _GDIPlus_ImageDispose($hImage) _GDIPlus_BitmapDispose($hBitmap) _GDIPlus_Shutdown() EndFunc ;==>Example
-
Deye got a reaction from dmob in Move rows on 2D array
#include <Array.au3> Dim $aArray[][] = [["A", 0], ["B", 0], ["C", 0], ["D", 0], ["E", 1], ["F", 1]] _ArrayDisplay(_ArrPopToTop($aArray, "B|D|F")) _ArrayDisplay(_ArrPopToTop($aArray, "D|E")) _ArrayDisplay(_ArrPopToTop($aArray, "C")) Func _ArrPopToTop($a, $val = "", $index = 0) Local $asplit = StringSplit($val, "|", 3) _ArrayReverse($asplit) For $j = 0 To UBound($asplit) - 1 $x = _ArraySearch($a, $asplit[$j], "", "", "", 0) _ArrayInsert($a, $index, _ArrayExtract($a, $x, $x)) _ArrayDelete($a, $x + 1) Next Return $a EndFunc
-
Deye reacted to Musashi in Simple Google Translate
Yes !
Here the script with a longer text :
#include "Json.au3" ; (by @AspirinJunkie) Global $sRead1 = 'This text will be translated into another language. ' & _ 'The Moderation team will do their best to act in fair and reasonable manner. Sanctions will ' & _ 'only be applied as a last resort and any action taken will be explained in the relevant thread. ' & _ 'If you feel that you have been unfairly moderated then contact the Moderator concerned - ' & _ 'using a PM or the "Report" button is preferable to opening a new thread (although new members ' & _ 'may have to do this). But do be aware that the Moderation team has the final word - the rules ' & _ 'are set out by the site owner and you are only welcome here if you respect his wishes.' ConsoleWrite("+ >> ORIGINAL: " & $sRead1 & @CRLF) ConsoleWrite("+ ------------------------------------------------------------------------------ " & @CRLF) ConsoleWrite("> >> EN->DE : " & _GoogleAPITranslate($sRead1, "en", "de") & @CRLF) ConsoleWrite("> >> EN->FR : " & _GoogleAPITranslate($sRead1, "en", "fr") & @CRLF) ConsoleWrite("> >> EN->ES : " & _GoogleAPITranslate($sRead1, "en", "es") & @CRLF) ; ------------ Function : --------------- Func _GoogleAPITranslate($sMytext, $sFrom, $sTo) Local $sUrl, $oHTTP, $sResponse, $JSONData, $sOutput = "", $aData $sUrl = "https://translate.googleapis.com/translate_a/single?client=gtx&sl=" & $sFrom & "&tl=" & $sTo & "&dt=t&q=" & $sMytext $oHTTP = ObjCreate("Microsoft.XMLHTTP") $oHTTP.Open("POST", $sUrl, False) $oHTTP.Send() $sResponse = $oHTTP.ResponseText $JSONData = _JSON_Parse($sResponse) If VarGetType($JSONData) = 'Array' Then $aData = $JSONData[0] If VarGetType($aData) = 'Array' Then For $i = 0 To UBound($aData) -1 Step 1 $sOutput &= ($aData[$i])[0] ;*** & @CRLF Next EndIf EndIf Return $sOutput EndFunc ;==>_GoogleAPITranslate Result :
-
Deye got a reaction from gogloc in Download a file reading first a local txt file which contains the full url
Try This:
#include <File.au3> $s = FileRead("mp3.txt") $aReadUrl = StringRegExp($s, "(?:http).+(?=\w\/)+[!-~]+\.\w{3}", 3) If IsArray($aReadUrl) Then ;~ MsgBox(0, StringRegExpReplace($aReadUrl[0], ".*\/", ""), $aReadUrl[0]) InetGet($aReadUrl[0], StringRegExpReplace($aReadUrl[0], ".*\/", ""), "", 2) ;~ _ArrayDisplay($aReadUrl, "File Url List") EndIf
-
Deye got a reaction from Skeletor in Catchy Replace example
Replace single characters on the left with anything specified between matching vertical bars on the right
$txt = "Jack's birthday is 02/02/02 & Jill's is the same" MsgBox(0, '', _PatternStringReplace($txt, "'/ &", "|-|_|And")) MsgBox(0, '', _PatternStringReplace($txt, "/&20", "2|could it be that")) MsgBox(0, '', _PatternStringReplace($txt, "j02/&'", "M")) Func _PatternStringReplace($sTxt, $sPatt, $sReplace) Local $a1 = StringSplit($sPatt, "") Local $a2 = StringSplit($sReplace, "|") ReDim $a2[UBound($a1)] Local $sda = ObjCreate("Scripting.Dictionary") For $i = 1 To UBound($a1) - 1 $sda.item($a1[$i]) = $a2[$i] If StringIsAlpha($a1[$i]) Then $sda.item(StringIsLower($a1[$i]) ? StringUpper($a1[$i]) : StringLower($a1[$i])) = $a2[$i] Next Return Execute('"' & StringRegExpReplace($sTxt, "(?i)([" & $sPatt & "])", '" & $sda.Item("$1") & "') & '"') EndFunc -
Deye got a reaction from vulcan4d in Comparing two values, equals or near (how to determine if near?) - (Moved)
Or even maybe this :
$iValue1 = 12445 $iValue2 = 12694 $PercentageOfChange = Abs(Round(($iValue2 - $iValue1) / $iValue1 * 10 ^ 2, 2)) ConsoleWrite("%" & $PercentageOfChange & @LF)
-
Deye reacted to Gianni in Are you smarter than a chimp?
After watching this movie (https://www.youtube.com/watch?v=cPiDHXtM0VA) I wanted to try the test to see how much i could compete with that chimpanzee so i created this script.
well, actually passing that test is a lot harder than it sounds. With the difficulty set to seven numbers and a display time of one second, I can only remember 2 or 3 numbers ... (what a disappointment)
I can only do better if I reduce the slider to 5 numbers and increase the storage time to 2 seconds (the easyest level), a very poor performance. That chimpanzee is great.
The script offers you a sequence of 10 random quizzes. At the end it gives you the percentage of your "level". The chimpanzee resolves on average 8 out of 10 (80%), so you can compare your performance to that of the chimpanzee.
How to play:
Run the script. At the beginning there are 2 sliders at the bottom of the screen where you can set the difficulty level by varying the memorization time and the amount of numbers to memorize as you like. After setting the difficulty, click the circle on the bottom left to get started. after the first move the sliders are no longer displayed until the next game, (the game lasts 10 attempts, there is a progress bar at the bottom of the screen to see where you are) between one test and the other of the ten, click on the circle to move on to the next test have fun.
(here a related interesting video: https://www.youtube.com/watch?v=ktkjUjcZid0 )
#include <GUIConstants.au3> #include <MsgBoxConstants.au3> #include <Array.au3> #include <WinAPIMisc.au3> ; HotKeySet("{ESC}", "_EndOfGame") Global $iNumbersToGuess = 7, $iExpositionTime = 1000, $iMatches = 10, $iMatchesWon Global $aNumbers[10] = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] Global $aButtons[10], $aControls[5] Global $iWinWidth = @DesktopWidth / 2, $iWinHeight = @DesktopHeight / 2, $iButtonXSide = Int($iWinWidth / UBound($aNumbers)), $iButtonYSide = Int($iWinHeight / UBound($aNumbers)), $sWinTitle = "Beat the Chimp" Global $aX[Int($iWinWidth / $iButtonXSide)], $aY[Int($iWinHeight / $iButtonYSide)], $iNdx = 0, $aPoints[3], $score, $GUIGetMsg, $iDockHeight = 50, $iProgrssHeight = 5 For $i = 0 To (Int($iWinWidth / $iButtonXSide) - 1) * $iButtonXSide Step $iButtonXSide $aX[$iNdx] = $i $iNdx += 1 Next $iNdx = 0 For $i = 0 To (Int($iWinHeight / $iButtonYSide) - 1) * $iButtonYSide Step $iButtonYSide $aY[$iNdx] = $i $iNdx += 1 Next Global Const $iDockLeftBorder = 200, $iForeColor = 0xFFFFFF, $iBackColor = 0x000000 Global $hGUI = GUICreate($sWinTitle, $iWinWidth, $iWinHeight + $iDockHeight + $iProgrssHeight, @DesktopWidth / 4, @DesktopHeight / 5) GUISetBkColor($iBackColor, $hGUI) ; the circle to continue playing $aControls[0] = GUICtrlCreateLabel(ChrW(0x25EF), 0, $iWinHeight + 1, 100, $iDockHeight, 0x01) ; GUICtrlSetTip(-1, "Click the circle," & @CRLF & "then click the squares" & @CRLF & "in numeric order.") GUICtrlSetFont(-1, 24, 900) GUICtrlSetColor(-1, $iForeColor) GUICtrlSetBkColor(-1, $iBackColor) ; slider for the amount of numbers to guess $aControls[2] = GUICtrlCreateSlider($iDockLeftBorder, $iWinHeight, $iWinWidth - $iDockLeftBorder, Int($iDockHeight / 2)) GUICtrlSetLimit(-1, 10, 5) ; 5 steps 5 (easy) to 10 (hard) GUICtrlSetData(-1, $iNumbersToGuess) ; label for the amount of quizzes $aControls[1] = GUICtrlCreateLabel("Numbers : " & GUICtrlRead($aControls[2]), 100, $iWinHeight + 1, 100) GUICtrlSetColor(-1, $iForeColor) ; slider for the exposition time $aControls[4] = GUICtrlCreateSlider($iDockLeftBorder, $iWinHeight + (Int($iDockHeight / 2)), $iWinWidth - $iDockLeftBorder, $iDockHeight / 2) GUICtrlSetLimit(-1, 8, 1) ; 8 steps (0f 250ms each) GUICtrlSetData(-1, $iExpositionTime / 250) ; label for the exposition time $aControls[3] = GUICtrlCreateLabel("ms to show : " & GUICtrlRead($aControls[4]) * 250, 100, $iWinHeight + 1 + (Int($iDockHeight / 2)), 100) GUICtrlSetColor(-1, $iForeColor) ; progress bar of the match Global $idProgressbar = GUICtrlCreateProgress(0, $iWinHeight + $iDockHeight, $iWinWidth, $iProgrssHeight) ; Create buttons For $i = 0 To 9 $aButtons[$i] = GUICtrlCreateLabel($i + 1, $iWinWidth + 5, $iWinHeight + $iDockHeight + $iProgrssHeight + 5, $iButtonXSide, $iButtonYSide, 0x01) GUICtrlSetFont($aButtons[$i], 24) GUICtrlSetColor($aButtons[$i], $iForeColor) GUICtrlSetBkColor($aButtons[$i], $iBackColor) Next GUISetState(@SW_SHOW) ; --- Main loop --- Do ; New game $iMatchesWon = 0 GUICtrlSetData($idProgressbar, 0) For $iRound = 1 To $iMatches ; the game lasts $iMatches rounds $iNdx = 0 ; reset pointer (index to the next correct answer) _HideControls(__get_IDs_by_indexes($aButtons, $aNumbers)) ; remove the numbers from the screen ; show the dock and wait (only in the first round are also shown the sliders) _ShowControls($iRound = 1 ? $aControls : $aControls[0]) ; display the dock's control(s) While 1 Switch GUIGetMsg() Case $aControls[0] ; The circle (play a new quiz) ExitLoop Case $aControls[2] ; slider to choose how many numbers to guess $iNumbersToGuess = GUICtrlRead($aControls[2]) GUICtrlSetData($aControls[1], "Numbers : " & $iNumbersToGuess) Case $aControls[4] ; slider to choose how long (milliseconds) to show the numbers $iExpositionTime = GUICtrlRead($aControls[4]) * 250 ; 8 steps of 250 milliseconds each GUICtrlSetData($aControls[3], "ms to show : " & $iExpositionTime) Case $GUI_EVENT_CLOSE _EndOfGame() EndSwitch WEnd _HideControls($aControls) ; hide the dock Sleep(750) ; wait a bit $aQuiz = _GenerateQuiz($iNumbersToGuess) ; generate random elements to guess _SpreadControls(__get_IDs_by_indexes($aButtons, $aQuiz)) ; scatter the numbers on the GUI _ShowControls(__get_IDs_by_indexes($aButtons, $aQuiz)) ; display the numbers Sleep($iExpositionTime) ; leave numbers visible for a short time _MaskControls(__get_IDs_by_indexes($aButtons, $aQuiz)) ; mask the numbers GUICtrlSetData($idProgressbar, Round($iRound / $iMatches * 100)) ; _ShowControls(__get_IDs_by_indexes($aButtons, $aQuiz)) ; <------------- keep numbers visible FOR DEBUG PURPOSE ONLY! While 1 ; wait for a move $GUIGetMsg = GUIGetMsg() If $GUIGetMsg = $GUI_EVENT_CLOSE Then _EndOfGame() ; scan all quiz buttons to check if one was pressed For $i = 0 To UBound($aQuiz) - 1 ; $aButtons) - 1 If $GUIGetMsg = $aButtons[$aQuiz[$i] - 1] Then If $i = $iNdx Then ; -------------------------- ; actions for a right move ; -------------------------- ; hide the guessed number _HideControls($aButtons[$aQuiz[$i] - 1]) ; --------------------------------- ; check if this round is complete ; --------------------------------- If $iNdx = (UBound($aQuiz) - 1) Then _WinAPI_PlaySound("SystemExclamation", Null, BitOR($SND_ALIAS, $SND_ASYNC)) $iMatchesWon += 1 ExitLoop 2 EndIf ; play a short ok sound ; _WinAPI_PlaySound("FaxBeep", Null, BitOR($SND_ALIAS, $SND_ASYNC)) ; "SystemAsterisk" $iNdx += 1 ; set index to next correct answer Else ; -------------------------- ; actions for a wrong move ; -------------------------- ; show all the right sequence _ShowControls(__get_IDs_by_indexes($aButtons, $aQuiz)) _WinAPI_PlaySound("DeviceFail", Null, BitOR($SND_ALIAS, $SND_ASYNC)) ; give a little time to the user to control it Sleep(1500) ; go to next step ExitLoop 2 EndIf EndIf Next WEnd ; loop till end of match $score = Round($iMatchesWon / $iMatches * 100, 2) ; percentage Select Case $score < 80 $sResult = "The chimp beat you!" Case $score > 80 $sResult = "You beat the chimp!" Case $score = 80 $sResult = "You tied the chimp." EndSelect Next ; next round ; game over? Until MsgBox($MB_YESNO + $MB_ICONINFORMATION + $MB_TASKMODAL + $MB_SETFOREGROUND, _ "Game over", _ "You got " & $score & "% correct." & @CRLF & _ "Ayumu averages 80% correct." & @CRLF & $sResult & @CRLF & @CRLF & _ "do you want to try again?") <> 6 Func _SpreadControls($aTemp) ; place the required numbers scattered on the GUI SRandom(@YEAR + @MON + @MDAY + @HOUR + @MIN + @SEC) _ArrayShuffle($aX) _ArrayShuffle($aY) ; first, place all buttons out of GUI For $i = 0 To UBound($aButtons) - 1 GUICtrlSetPos($aButtons[$i], $iWinWidth + 5, $iWinHeight + $iDockHeight + $iProgrssHeight + 5) GUICtrlSetState($aButtons[$i], $GUI_DISABLE) Next ; Then place only the numbers of this quiz in visible area For $i = 0 To UBound($aTemp) - 1 GUICtrlSetPos($aTemp[$i], $aX[$i], $aY[$i]) GUICtrlSetState($aTemp[$i], $GUI_ENABLE) Next EndFunc ;==>_SpreadControls Func _GenerateQuiz($iNumElements) ; generate an array of required random numbers SRandom(@YEAR + @MON + @MDAY + @HOUR + @MIN + @SEC) Local $aTemp[$iNumElements] _ArrayShuffle($aNumbers) For $i = 0 To $iNumElements - 1 $aTemp[$i] = $aNumbers[$i] Next _ArraySort($aTemp) Return $aTemp EndFunc ;==>_GenerateQuiz Func _ShowControls($aTemp) ; render controls visible (and enabled) $aTemp = _EnforceArray($aTemp) For $i = 0 To UBound($aTemp) - 1 GUICtrlSetState($aTemp[$i], $GUI_SHOW) GUICtrlSetColor($aTemp[$i], $iForeColor) GUICtrlSetBkColor($aTemp[$i], $iBackColor) Next EndFunc ;==>_ShowControls Func _MaskControls($aTemp) ; mask the controls $aTemp = _EnforceArray($aTemp) For $i = 0 To UBound($aTemp) - 1 GUICtrlSetColor($aTemp[$i], $iForeColor) GUICtrlSetBkColor($aTemp[$i], $iForeColor) Next EndFunc ;==>_MaskControls Func _HideControls($aTemp) ; hide the controls (implies disable) $aTemp = _EnforceArray($aTemp) For $i = 0 To UBound($aTemp) - 1 GUICtrlSetState($aTemp[$i], $GUI_HIDE) ; $GUI_DISABLE) ; GUICtrlSetColor($aButtons[$aTemp[$i] - 1], $iBackColor) ; GUICtrlSetBkColor($aButtons[$aTemp[$i] - 1], $iBackColor) Next EndFunc ;==>_HideControls Func _EnforceArray($vParam) ; if only one value is passed, turn it into an array of only 1 element If Not IsArray($vParam) Then Local $aTemp[1] = [$vParam] Return $aTemp EndIf Return $vParam EndFunc ;==>_EnforceArray Func __get_IDs_by_indexes(ByRef $aCtrls, ByRef $aNdxs) ; returns the handles of the controls pointed to by the indexes Local $aTemp[UBound($aNdxs)] For $i = 0 To UBound($aNdxs) - 1 $aTemp[$i] = $aCtrls[$aNdxs[$i] - 1] Next Return $aTemp EndFunc ;==>__get_IDs_by_indexes Func _EndOfGame() ; _WinAPI_PlaySound ("SystemExit" , Null, $SND_ALIAS) GUIDelete() Exit EndFunc ;==>_EndOfGame P.S. At this link (https://web.archive.org/web/20131006161544/http://games.lumosity.com/chimp.html) there is a Flash version of this game.
-
Deye got a reaction from Giggo in Database with Sqlite3.dll (I look for others solutions)
First try to implement this example into your script. and see what works for you
; at the top of your script set an array size that will match the number of controls you want to read Global $ARR[10] ; gui and controls creation .etc
For $i = 1 To UBound($ARR) - 1 $ARR[$i] = GUICtrlRead(Eval("e_Edit" & $i)) Next _arraydisplay($ARR) Or otherwise use\run your controls straight from an array where you read the controls from $agui[$i][0] that keeps a control's id in example 1 till 4
#include <File.au3> #include <GuiEdit.au3> $hGui = GUICreate("Sqlite GUI test", 1150, 650, -1, -1) Local $VGui = '' _ & 'Ctrl|Placement|GUICtrlCreate|Name|' _ & @CRLF & 'id|, 130, 5, 500, 200|Edit|' _ & @CRLF & 'id|, 640, 5, 500, 200|Edit|' _ & @CRLF & 'id|, 130, 200, 500, 200|Edit|' _ & @CRLF & 'id|, 640, 200, 500, 200|Edit|' _ & @CRLF & 'id|, 131, 616, 75, 25|Button|Add' _ & @CRLF & 'id|, 208, 616, 75, 25|Button|Delete' _ & @CRLF & 'id|, 208, 616, 75, 25|Button|Delete2' _ & @CRLF & 'id|, 5, 5, 120, 30|Button|Mostra 1' _ & @CRLF & 'id|, 5, 45, 120, 30|Button|Mostra 2' Local $aGui[0][5] _ArrayAdd($aGui, $VGui) For $i = 1 To UBound($aGui) - 1 $aGui[$i][0] = Execute("GUICtrlCreate" & $aGui[$i][2] & '("' & ($aGui[$i][3] ? $aGui[$i][3] & '"' : '"') & $aGui[$i][1] & ")") Next For $i = 1 To 4 _GUICtrlEdit_SetText($aGui[$i][0], "test" & $i) Next GUISetState(@SW_SHOW) For $i = 1 To 4 $aGui[$i][4] = GUICtrlRead($aGui[$i][0]) Next _ArrayDisplay($aGui)
-
Deye got a reaction from Doniel in File Settings
Funnily windows 10 is not a finished product and still people will expect things to work as if it was "windows xp" , maybe this will be fixed in windows 11
-
Deye got a reaction from ARPFre in Getting data from a table in TXT.
For fun, a case sensitive search example
#include <Array.au3> $file = "InstallSoftware.txt" _Read($file, 'Acrobat') _Read($file, 'Silverlight') _Read($file, 'Kaspersky') _Read($file, 'AnyConnect') _Read($file, 'Microsoft Visual C') Func _Read($file, $sString) $a = StringSplit(StringRegExpReplace(StringRegExp(FileRead($file), "(?i)[\w ]+\Q" & $sString & "\E.*", 1)[0], '\s{3,}', "|"), "|", 2) $a[0] = StringRegExpReplace($a[0], "(\d{4})(\d{2})(\d{2})(.*)", "$1/$2/$3") _ArrayDisplay($a, $sString) EndFunc
-
Deye reacted to mikell in StringRegExp Capture
Honestly I can't remember this thing
In such cases I personally use a small func to first remove empty lines and lines containing the unwanted string - or several unwanted strings, in this case write them in the $filter param with a separator (here I used a semicolon)
#include <Array.au3> $sPattern = '(?ims)^\h*(?|(?:local|Global)\h+(\N+)|((?|\$|GUI[cs])\N+))(?=.*GUISetState)' _Read("GUICtrlCreateDummy.au3") _Read("_WinAPI_CallWindowProc.au3") _Read("GUICtrlCreateContextMenu[2].au3") Func _Read($file) Local $sPath = @ProgramFilesDir & "\AutoIt3\Examples\Helpfile\" $txt = _clean(FileRead($sPath & $file), "GUICtrlCreateDummy()") _ArrayDisplay(StringRegExp($txt, $sPattern, 3)) EndFunc Func _clean($txt, $filter, $separator = ";") $filter = "\Q" & StringReplace($filter, $separator, "\E|\Q") & "\E" Return StringRegExpReplace($txt, '(?m)^(\s*|.*(?:' & $filter & ').*)$\R?', "") EndFunc
-
Deye reacted to Gianni in SRER challenge
what does 'SRER' mean?
... here my bark belch...
#include <String.au3> #include <Array.au3> $sVar = @LF & @CRLF _ & 'MainWindowHandle : 132730' _ & @LF & 'Id : 8808' _ & @LF & 'ProcessName : SciTE' _ & @LF & 'CPU : 112.15625' _ & @LF & 'Handles : 512' & @LF & @CRLF $sVar &= 'MainWindowHandle : 656932' _ & @LF & 'Id : 4268' _ & @LF & 'ProcessName : iexplore' _ & @LF & 'CPU : 0.15625' _ & @LF & 'Handles : 400' & @LF & @CRLF $sVar &= 'MainWindowHandle : 1182078' _ & @LF & 'Id : 6748' _ & @LF & 'ProcessName : explorer' _ & @LF & 'CPU : 12.09375' _ & @LF & 'Handles : 1230' & @LF & @CRLF $sVar &= 'MainWindowHandle : 1837220' _ & @LF & 'Id : 6868' _ & @LF & 'ProcessName : explorer' _ & @LF & 'CPU : 6.171875' _ & @LF & 'Handles : 552' & @LF & @CRLF ; ---------------- $sVar = StringReplace($sVar, @LF & @CR, @CR) Local $aHeaders = _ArrayUnique(_StringBetween($sVar, @LF, ':'), 0, 0, 0, 0) Local $s = _ArrayToString($aHeaders) & @LF ; _ArrayDisplay($aHeaders) For $i = 0 To UBound($aHeaders) - 1 $sVar = StringReplace($sVar, $aHeaders[$i] & ": ", "") Next $sVar = StringReplace($sVar, @LF, '|') Local $aRecords = _StringBetween($sVar, @CR, @CR) For $i = 0 To UBound($aRecords) - 1 $s &= StringTrimLeft($aRecords[$i], 1) & @LF Next $s = StringTrimRight($s, 1) ConsoleWrite($s & @LF) ; goal ; ---------------- _ArrayDisplay(_VarTo2D($s, "|")) Func _VarTo2D($var, $sSeparator = @TAB) Local $aRows = StringSplit(StringStripCR($var), @LF), $aColumns, $aResult[$aRows[0]][1] For $iRow = 1 To $aRows[0] $aColumns = StringSplit($aRows[$iRow], $sSeparator) If $aColumns[0] > UBound($aResult, 2) Then ReDim $aResult[$aRows[0]][$aColumns[0]] For $iColumn = 1 To $aColumns[0] $aResult[$iRow - 1][$iColumn - 1] = $aColumns[$iColumn] Next Next Return $aResult EndFunc ;==>_VarTo2D
-
Deye reacted to mikell in Possible to change order of lines in text file based on number?
For the fun
#Include <Array.au3> $txt = "Objects (id: bounding-box centroid area mean-color):" & @crlf & _ " 0: 280x80+0+0 140.8,39.4 20069 gray(0)" & @crlf & _ " 4: 25x27+136+26 148.4,38.9 342 gray(255)" & @crlf & _ " 5: 25x26+34+27 48.9,39.9 307 gray(255)" & @crlf & _ " " & @crlf & _ " 6: 26x25+65+27 77.5,39.3 292 gray(255)" & @crlf & _ " 11: 33x18+211+34 227.7,41.3 289 gray(255)" & @crlf & _ " 9: 23x26+111+34 122.1,44.3 254 gray(255)" & @crlf & _ "" & @crlf & _ " 7: 16x19+70+30 77.8,39.0 219 gray(0)" & @crlf & _ " 2: 25x27+163+25 172.0,36.5 199 gray(255)" & @crlf & _ " 10: 20x18+187+34 197.2,41.6 179 gray(255)" & @crlf & _ " 3: 15x26+95+26 101.2,37.1 153 gray(255)" & @crlf & _ " 13: 11x11+116+37 121.1,42.2 97 gray(0)" $txt = StringRegExpReplace($txt, '(^.+\R)|(?m)^(\s*\R)|(.*gray\(0\)\R?)', "") $stmp = Execute("'" & StringRegExpReplace($txt, "(?m)(^.*?)(?<=\h)(\d+)(?=\.)", "' & StringFormat('%04i', '$2') & ' $1$2' & '") & "'") $atmp = StringRegExp($stmp, '\N+', 3) _ArraySort($atmp, 1) $res = StringRegExpReplace(_ArrayToString($atmp, @crlf), '(?m)^\d{4}\h*', "") Msgbox(0,"", $res)
-
Deye got a reaction from FrancescoDiMuro in [Solved] Regular expression to capture multiple groups with prefix
without too much of examining how, this somehow moves everything to the top
"(User|Login-name|NTSecurity|Member):\s(.*)|(.+)\r\n?(?:\r?\n)"
-
Deye got a reaction from FrancescoDiMuro in [Solved] Regular expression to capture multiple groups with prefix
this seems to work:
"(User|Login-name|NTSecurity|Member):\s(.*)|.+\r\n?"
-
Deye got a reaction from FrancescoDiMuro in [Solved] Regular expression to capture multiple groups with prefix
Please Try:
$sText = FileRead("SECURITY.RPT") $sNames = "User|Login-name|Member|Domain|NTSecurity" $s = StringRegExpReplace($sText, _ ".*(?:" & $sNames & "):\s(.*)|(.+)\R", "\1") ConsoleWrite(StringStripWS($s, 3) & @CRLF)
-
Deye reacted to Nine in [Solved] Regular expression to capture multiple groups with prefix
Dam How do you know fishing is my second life ?
-
Deye got a reaction from FrancescoDiMuro in [Solved] Regular expression to capture multiple groups with prefix
No worries, until then, we'll go fishing with 9 to cool him down a bit.