dany Posted August 20, 2012 Share Posted August 20, 2012 _StringFormatEx does the same as StringFormat but with added support for argument swapping. I originally wrote it as a support function for a bigger UDF but it can stand well on its own. Format pattern is: %[placeholder$] [flags] [width] [.precision] typeHave fun with it.expandcollapse popup; _StringFormatEx example. ; Lets put this in the right order. n$ denotes a numbered (n) placeholder ; that gets replaced with the n-th argument passed to _StringFormatEx, no ; matter what the order is in the string. Local $sFormat = '%4$s %7$s %1$s %8$s %2$s %5$s %9$s %3$s %6$s.' MsgBox(0, '_StringFormatEx 1', _StringFormatEx($sFormat, 'onyx', 'jumps', 'lazy', 'The', 'over', 'dwarf', 'quick', 'goblin', 'the')) ; All other formatting is still supported. MsgBox(0, '_StringFormatEx 2', _StringFormatEx('%3$X %1$+d [%2$10s]', -43951789, 'monkey', 43951789)) #cs Name: _StringFormatEx Description: Does the same as StringFormat but with added support for argument swapping. Format pattern is: %[placeholder$] [flags] [width] [.precision] type Author: dany Parameters: $sStr - String: String to format. $v1 - $v32 - Mixed: Replacement values to insert. Return values: Success: - String: Formatted string. Failure: - 0 and sets @error and @extended. @extended values: 1: Invalid argument (not a String). Remarks: Do not mix placeholders with non-placeholders e.g.: _StringFormatEx('%s %1$s', 'world', 'hello') It will NOT work. #ce Func _StringFormatEx($sStr, $v1, $v2 = '', $v3 = '', $v4 = '', _ $v5 = '', $v6 = '', $v7 = '', $v8 = '', $v9 = '', _ $v10 = '', $v11 = '', $v12 = '', $v13 = '', $v14 = '', _ $v15 = '', $v16 = '', $v17 = '', $v18 = '', $v19 = '', _ $v20 = '', $v21 = '', $v22 = '', $v23 = '', $v24 = '', _ $v25 = '', $v26 = '', $v27 = '', $v28 = '', $v29 = '', _ $v30 = '', $v31 = '', $v32 = '' _ ) If Not IsString($sStr) Then Return SetError(1, 1, 0) Local $i, $iMax, $sVal Local $aParams, $aCallArgArray[@NumParams + 1] $aCallArgArray[0] = 'CallArgArray' $aParams = StringRegExp($sStr, '%([0-9]{1,2})$[-+. #0-9diouxXeEfgGs]', 3) ; Get indexes. If @error Then Return StringFormat($sStr, $v1, $v2, _ $v3, $v4, $v5, $v6, $v7, $v8, $v9, $v10, $v11, $v12, $v13, $v14, $v15, _ $v16, $v17, $v18, $v19, $v20, $v21, $v22, $v23, $v24, $v25, $v26, $v27, _ $v28, $v29, $v30, $v31, $v32) ; Standard StringFormat. $aCallArgArray[1] = StringRegExpReplace($sStr, '%([0-9]{1,2}$)([-+. #0-9diouxXeEfgGs])', '%$2') ; Normalize parameters in original string. $iMax = UBound($aParams) - 1 For $i = 0 To $iMax ; Reorder arguments. $sVal = Eval('v' & Int($aParams[$i])) $aCallArgArray[$i + 2] = $sVal Next Return Call('__StringFormatEx_Callback', $aCallArgArray) EndFunc ; Private helper function of _StringFormatEx Func __StringFormatEx_Callback($sStr, $v1, $v2 = '', $v3 = '', $v4 = '', _ $v5 = '', $v6 = '', $v7 = '', $v8 = '', $v9 = '', _ $v10 = '', $v11 = '', $v12 = '', $v13 = '', $v14 = '', _ $v15 = '', $v16 = '', $v17 = '', $v18 = '', $v19 = '', _ $v20 = '', $v21 = '', $v22 = '', $v23 = '', $v24 = '', _ $v25 = '', $v26 = '', $v27 = '', $v28 = '', $v29 = '', _ $v30 = '', $v31 = '', $v32 = '' _ ) Return StringFormat($sStr, $v1, $v2, $v3, $v4, $v5, $v6, $v7, $v8, $v9, $v10, _ $v11, $v12, $v13, $v14, $v15, $v16, $v17, $v18, $v19, $v20, $v21, $v22, _ $v23, $v24, $v25, $v26, $v27, $v28, $v29, $v30, $v31, $v32) ; Standard StringFormat. EndFuncAs always, let me know about any bugs or improvements you might see. [center]Spiderskank Spiderskank[/center]GetOpt Parse command line options UDF | AU3Text Program internationalization UDF | Identicon visual hash UDF Link to comment Share on other sites More sharing options...
JScript Posted August 20, 2012 Share Posted August 20, 2012 The columns are scaled only when the window is resized, I've changed the description of snippets! See an Gif of first LV autoresize: https://dl.dropbox.com/s/vt5gsvf2hobmbhq/_GUICtrlListView_AutoResizeColumn.gif?dl=1 Best regards, João Carlos. http://forum.autoitbrasil.com/ (AutoIt v3 Brazil!!!) Somewhere Out ThereJames Ingram Download Dropbox - Simplify your life!Your virtual HD wherever you go, anywhere! Link to comment Share on other sites More sharing options...
AZJIO Posted August 21, 2012 Share Posted August 21, 2012 MsgBox(0, '', _Reg_Exists('HKEY_CURRENT_USERSoftwareMicrosoftWindowsShellNoRoamMUICache')) Func _Reg_Exists($sKey) RegRead($sKey, '') Return Not (@error > 0) EndFunc My other projects or all Link to comment Share on other sites More sharing options...
dany Posted August 28, 2012 Share Posted August 28, 2012 (edited) edit: Calculate the bit entropy of a password. The higher the bit entropy, the harder it is to guess/bruteforce the password.expandcollapse popup#cs _CalculateBitEntropy Name: _CalculateBitEntropy Description: Calculate the bit entropy of a string. Author: dany Parameters: $sStr - String: String to evaluate. $fCase - Boolean: Do case-sensitive evaluation, default true. Return values: Success: - Float: Bit entropy. Failure: - 0 and sets @error Link: http://en.wikipedia.org/wiki/Password_strength#Entropy_as_a_measure_of_password_strength #ce Func _CalculateBitEntropy($sStr, $fCase = True) If IsBinary($sStr) Then $sStr = BinaryToString($sStr) If Not IsString($sStr) Then Return SetError(1, 0, 0) Local $aDice, $iH = 0, $iLen = StringLen($sStr) If 0 = $iLen Then Return SetError(2, 0, 0) $aDice = StringSplit($sStr, ' ') If 1 < $aDice[0] Then Return $aDice[0] * 12.925 If StringIsDigit($sStr) Then $iH = 3.3219 ElseIf StringIsXDigit($sStr) Then $iH = 4.0000 ElseIf StringIsAlpha($sStr) Then $iH = 4.7004 If $fCase Then If StringRegExp($sStr, '[a-z]+') And StringRegExp($sStr, '[A-Z]+') Then $iH = 5.7004 EndIf ElseIf StringIsAlNum($sStr) Then $iH = 5.1699 If $fCase Then If StringRegExp($sStr, '[a-z]+') And StringRegExp($sStr, '[A-Z]+') Then $iH = 5.9542 EndIf ElseIf StringRegExp($sStr, '^[^[:cntrl:]x7F]+$') Then $iH = 6.5699 ElseIf _StringRegExp($sStr, '^[^[:cntrl:]x7Fx81x8Dx8Fx90x9D]+$') Then $iH = 7.7682 EndIf Return $iH * $iLen EndFuncExample:#include <CalculateBitEntropy.au3> Local $sPassA = 'Tr0ub4dor&3' ; Passphrase. Local $sPassB = 'correct horse battery staple' MsgBox(0, '_CalculateBitEntropy', $sPassA & ': ' & _CalculateBitEntropy($sPassA) & @CRLF & $sPassB & ': ' & _CalculateBitEntropy($sPassB)) Edited October 5, 2012 by dany [center]Spiderskank Spiderskank[/center]GetOpt Parse command line options UDF | AU3Text Program internationalization UDF | Identicon visual hash UDF Link to comment Share on other sites More sharing options...
dany Posted August 28, 2012 Share Posted August 28, 2012 (edited) Calculate the bit entropy of a password according to NIST Special Publication 800-63. The higher the entropy, the harder to guess. This is the calculation method used in xkcd 936.#cs _CalculateBitEntropyNIST Name: _CalculateBitEntropyNIST Description: Calculate the bit entropy of a string according to NIST Special Publication 800-63. Author: dany Parameters: $sStr - String: String to evaluate. Return values: Success: - Float: Bit entropy. Failure: - 0 and sets @error Remarks: This is the algorithm used in http://xkcd.com/936/. Link: http://en.wikipedia.org/wiki/Password_strength#Human-generated_passwords #ce Func _CalculateBitEntropyNIST($sStr) If IsBinary($sStr) Then $sStr = BinaryToString($sStr) If Not IsString($sStr) Then Return SetError(1, 0, 0) Local $iNist = 4, $iLen = StringLen($sStr) If 0 = $iLen Then Return SetError(2, 0, 0) $iLen -= 1 While $iLen <> 0 If $iLen > 19 Then $iNist += 1 ElseIf $iLen > 7 Then $iNist += 1.5 Else $iNist += 2 EndIf $iLen -= 1 WEnd If StringRegExp($sStr, '[[:upper:]]') Then If StringRegExp($sStr, '[^[:alpha:]]') Then $iNist += 6 EndIf Return $iNist EndFuncExample:#include <CalculateBitEntropyNIST.au3> Local $sPassA = 'Tr0ub4dor&3' ; Passphrase. Local $sPassB = 'correct horse battery staple' MsgBox(0, '_CalculateBitEntropyNIST', $sPassA & ': ' & _CalculateBitEntropyNIST($sPassA) & @CRLF & $sPassB & ': ' & _CalculateBitEntropyNIST($sPassB))edit: optimized regexp. Edited October 5, 2012 by dany [center]Spiderskank Spiderskank[/center]GetOpt Parse command line options UDF | AU3Text Program internationalization UDF | Identicon visual hash UDF Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted August 29, 2012 Moderators Share Posted August 29, 2012 (edited) Someone requested this today, and I thought I would expand it a bit into a snippet ;Checks a remote PC for it's MAC Address. Can use PC Name or IP Address _FindMAC() Func _FindMAC() $PC = InputBox("Remote MAC", "Enter the name of the computer to get the MAC address") If Ping($PC) Then ;verify connectivity first. $WMI = ObjGet("winmgmts:\\" & $PC & "\root\cimv2") ;connect to WMI on remote machine $query = $WMI.ExecQuery _ ("Select * From Win32_NetworkAdapterConfiguration Where IPEnabled = True") ;query remote machine for NIC Configuration For $element in $query MsgBox(0, "Remote MAC", $element.MACAddress) ;For each network adapter, report MAC Address Next Else MsgBox(0, "Remote MAC", "Unable to Ping " & $PC) EndIf EndFunc ;===>_FindMAC Edited August 29, 2012 by JLogan3o13 "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
JScript Posted August 30, 2012 Share Posted August 30, 2012 A simple snippet to support printing files or texts from our programs in AutoIt! expandcollapse popup; #FUNCTION# ==================================================================================================================== ; Name ..........: _PrintFileOrText ; Description ...: Simple support printing files or texts! ; Syntax ........: _PrintFileOrText($vValue[, $fWaiting = True]) ; Parameters ....: $vValue - File name or texto! ; $fWaiting - [optional] If True, wait to impression. Default is True. ; Return values .: None ; Author ........: JScript ; Modified ......: ; Remarks .......: ; Related .......: ; Link ..........: ; Example .......: No ; =============================================================================================================================== Func _PrintFileOrText($vValue, $fWaiting = True) Local $sFileName, $iRandom = 0 If FileExists($vValue) Then $sFileName = $vValue Else $iRandom = 1 $sFileName = @TempDir & "" & Random(111111, 999999, 1) & ".tmp" ; Generates a random file name... ; Writes the contents to be printed... $hFileOpen = FileOpen($sFileName, 2) FileWrite($hFileOpen, $vValue) FileClose($hFileOpen) EndIf Switch $fWaiting Case True RunWait(@SystemDir & "notepad.exe /p " & FileGetShortName($sFileName), "", @SW_HIDE) Case False Run(@SystemDir & "notepad.exe /p " & FileGetShortName($sFileName), "", @SW_HIDE) EndSwitch If $iRandom Then FileDelete($sFileName) Return 1 EndFunc ;==>_Print Skysnake 1 http://forum.autoitbrasil.com/ (AutoIt v3 Brazil!!!) Somewhere Out ThereJames Ingram Download Dropbox - Simplify your life!Your virtual HD wherever you go, anywhere! Link to comment Share on other sites More sharing options...
jmon Posted September 3, 2012 Share Posted September 3, 2012 StringTrimPattern, a pretty cool function expandcollapse popup; Trim a pattern of characters from left '>', right '<' or both ( '<>' or '><' ) | Default trims from right _Print( StringTrimPattern('####Trim from left####', '#', '>')) ;use '>' to trim from left _Print( StringTrimPattern('####Trim from right####', '#', '<')) ;use '<' to trim from right _Print( StringTrimPattern('####trim from both sides####', '#', '<>')) ;use '<>' or '><' to trim from both sides _Print( StringTrimPattern('_><_%__Advanced test from both sides_%%_/__', '%_<>/', '<>')) ;use '<>' to trim from both sides _Print( StringTrimPattern('C:folder', '', '<')) ;trim backslashes from right _Print( StringTrimPattern('C:folderimageSequence_005484.051', '0123456789._', '<')) ;Trim image numbering _Print( StringTrimPattern('C:folderimageSequence_005484-051.tga', '0123456789abcdefghijklmnopqrstuvwxyz _-./', '<')) ;Trim to root _Print( StringTrimPattern('C:folderimageSequence_005484-051.tga', 'abcdefghijklmnopqrituvwxyz:', '>')) ;Trim root _Print( StringTrimPattern('Remove trailing white spaces ', ' ', '<')) ;Trim white spaces _Print( StringTrimPattern('Remove new lines @CRLF' & @CRLF & @CRLF, @CRLF, '<')) ;Trim new lines _Print( StringTrimPattern('Image.tga', 'tgajpgpng', '<')) ;Trim various image file extentions _Print( StringTrimPattern('Image.jpg', 'tgajpgpng', '<')) ;Trim various image file extentions _Print( StringTrimPattern('C:folderprogram.exe', 'ex', '<')) ;Trim the extention _Print( StringTrimPattern('Non case SensitiveXXXxxx', 'x', '<')) ;not case sensitive _Print( StringTrimPattern('Case SensitiveXXXxxx', 'x', '<', 1)) ;case sense test (same options as StringCompare ) Exit Func StringTrimPattern($sString, $sPattern, $sDirection = '<', $iCaseSense = 0) If $sDirection <> '>' And $sDirection <> '<' And $sDirection <> '<>' And $sDirection <> '><' Then Return SetError(1, 0, "") EndIf Local $a, $b, $sChar $a = StringSplit($sPattern, '') $b = StringSplit($sDirection, '') For $i = 1 To $b[0] While 1 If $b[$i] = '>' Then $sChar = StringLeft($sString, 1) Else $sChar = StringRight($sString, 1) EndIf For $i2 = 1 To $a[0] If StringCompare($a[$i2], $sChar, $iCaseSense) = 0 Then If $b[$i] = '>' Then $sString = StringTrimLeft($sString, 1) ContinueLoop 2 Else $sString = StringTrimRight($sString, 1) ContinueLoop 2 EndIf EndIf Next ExitLoop 1 WEnd Next Return $sString EndFunc ;==>StringTrimPattern Func _Print($sMsg) ;only used for demonstration purpose and clarity ConsoleWrite($sMsg & @CRLF) EndFunc ;==>_Print [center]www.jmontserrat.comFile Sequence UDF - _StringExtractPaths - _StringTrimPattern - GuiCtrlSetOnTop - CalendarUDF[/center] Link to comment Share on other sites More sharing options...
PhoenixXL Posted September 9, 2012 Share Posted September 9, 2012 (edited) To Find the IP is Private or Public expandcollapse popup;Example ConsoleWrite('is_privateIP::113.19.128.53 ='&is_privateIP('113.19.128.53')&@CR) ConsoleWrite('is_privateIP::'&@IPAddress1&' ='&is_privateIP(@IPAddress1)&@CR) ; #FUNCTION# ==================================================================================================================== ; Name ..........: is_privateIP ; Description ...: Get if the IP is Private ; Syntax ........: is_privateIP($nIp) ; Parameters ....: $nIp - The IP to be checked ; Return values .: 1 - IP is Private ; 2 - IP is Public ; Author ........: Phoenix XL ; Modified ......: ; Remarks .......: ; Related .......: ; Link ..........: ; Example .......: Yes ; =============================================================================================================================== Func is_privateIP($nIp) Local $pri_addrs[5] = [ _ '10.0.0.0|10.255.255.255', _ '172.16.0.0|172.31.255.255', _ '192.168.0.0|192.168.255.255', _ '169.254.0.0|169.254.255.255', _ '127.0.0.0|127.255.255.255' _ ]; Local $aAssign, $start, $end Local $long_ip = ip2long($nIp) If $long_ip = -1 Then Return SetError(1, 0, -1) For $pri_addr In $pri_addrs $aAssign = StringSplit($pri_addr, '|', 2); $start = ip2long($aAssign[0]) $end = ip2long($aAssign[1]) ; IF IS PRIVATE If $long_ip >= $start And $long_ip <= $end Then Return True Next Return False; EndFunc ;==>is_privateIP ; #FUNCTION# ==================================================================================================================== ; Name ..........: ip2long ; Description ...: Convert the IPv4 into Long ; Syntax ........: is_privateIP($nIp) ; Parameters ....: $nIp - The IP to be checked ; Return values .: Success - The Long Value of the Ip ; Failure - Returns -1 [Ip parameter is badly formatted] ; Author ........: Ptrex ; Modified ......: ; Remarks .......: ; Related .......: ; Link ..........: ; Example .......: No ; =============================================================================================================================== Func ip2long($nIp) $split = StringSplit($nIp, '.') If $split[0] < 4 Then Return -1 $long = ($split[1] * 16777216) + ($split[2] * 65536) + ($split[3] * 256) + ($split[4] * 1) Return $long EndFunc ;==>ip2long Edited September 10, 2012 by PhoenixXL My code: PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners. MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression. Link to comment Share on other sites More sharing options...
FireFox Posted September 26, 2012 Share Posted September 26, 2012 (edited) BASIC TCP Sender/Receiver with comments, because few people continue asking on it and UDFs available do not explain how it works.Notes : These examples are now available in the beta version 3.3.9.11+expandcollapse popup; I am the server, start me first! (Start in second the below example script). #include <Constants.au3> Example() Func Example() TCPStartup() ; Start the TCP service. ; Register OnAutoItExit to be called when the script is closed. OnAutoItExitRegister("OnAutoItExit") ; Assign Local variables the loopback IP Address and the Port. Local $sIPAddress = "127.0.0.1" ; This IP Address only works for testing on your own computer. Local $iPort = 65432 ; Port used for the connection. ; Assign a Local variable the socket and bind to the IP Address and Port specified with a maximum of 100 pending connexions. Local $iListenSocket = TCPListen($sIPAddress, $iPort, 100) ; If an error occurred display the error code and return False. If @error Then ; Someone is probably already listening on this IP Address and Port (script already running?). MsgBox(BitOR($MB_SYSTEMMODAL, $MB_ICONHAND), "", "Server: Could not listen, Error code: " & @error) Return False EndIf ; Assign a Local variable to be used by the Client socket. Local $iSocket = 0 Do ; Wait for someone to connect (Unlimited). ; Accept incomming connexions if present (Socket to close when finished; one socket per client). $iSocket = TCPAccept($iListenSocket) ; If an error occurred display the error code and return False. If @error Then MsgBox(BitOR($MB_SYSTEMMODAL, $MB_ICONHAND), "", "Server: Could not accept the incoming connection, Error code: " & @error) Return False EndIf Until $iSocket <> -1 ;if different from -1 a client is connected. ; Close the Listening socket to allow afterward binds. TCPCloseSocket($iListenSocket) ; Assign a Local variable the data received. Local $sReceived = TCPRecv($iSocket, 4) ;we're waiting for the string "tata" OR "toto" (example script TCPRecv): 4 bytes length. ; Notes: If you don't know how much length will be the data, ; use e.g: 2048 for maxlen parameter and call the function until the it returns nothing/error. ; Display the string received. MsgBox($MB_SYSTEMMODAL, "", "Server: Received: " & $sReceived) ; Close the socket. TCPCloseSocket($iSocket) EndFunc ;==>Example Func OnAutoItExit() TCPShutdown() ; Close the TCP service. EndFunc ;==>OnAutoItExitexpandcollapse popup; I am the client, start me after the server! (Start first the above example script). #include <Constants.au3> Example() Func Example() TCPStartup() ; Start the TCP service. ; Register OnAutoItExit to be called when the script is closed. OnAutoItExitRegister("OnAutoItExit") ; Assign Local variables the loopback IP Address and the Port. Local $sIPAddress = "127.0.0.1" ; This IP Address only works for testing on your own computer. Local $iPort = 65432 ; Port used for the connection. ; Assign a Local variable the socket and connect to a listening socket with the IP Address and Port specified. Local $iSocket = TCPConnect($sIPAddress, $iPort) ; If an error occurred display the error code and return False. If @error Then ; The server is probably offline/port is not opened on the server. MsgBox(BitOR($MB_SYSTEMMODAL, $MB_ICONHAND), "", "Client: Could not connect, Error code: " & @error) Return False EndIf ; Send the string "tata" to the server. TCPSend($iSocket, "tata") ; If an error occurred display the error code and return False. If @error Then MsgBox(BitOR($MB_SYSTEMMODAL, $MB_ICONHAND), "", "Client: Could not send the data, Error code: " & @error) Return False EndIf ; Close the socket. TCPCloseSocket($iSocket) EndFunc ;==>Example Func OnAutoItExit() TCPShutdown() ; Close the TCP service. EndFunc ;==>OnAutoItExit Edited July 31, 2013 by FireFox Link to comment Share on other sites More sharing options...
guinness Posted September 27, 2012 Share Posted September 27, 2012 I hope you don't mind but I tidied up your example and created a similar structure to ConsoleWrite(_Rot47('Example use of applying ROT47 to a string of text.') & @CRLF) ConsoleWrite(_Rot47(_Rot47('Example use of applying ROT47 to a string of text.')) & @CRLF) ; Version: 1.00. AutoIt: V3.3.8.1 ; Convert a string into ROT47. [https://en.wikipedia.org/wiki/ROT13] Func _Rot47($sString) ; deltarocked Local $iPosition = 0, $sReturn = '' For $i = 1 To StringLen($sString) $iPosition = StringMid($sString, $i, 1) If Asc($iPosition) + 47 >= 127 And Asc($iPosition) > 32 And Asc($iPosition) < 127 Then $sReturn &= Chr(Asc($iPosition) - 47) ElseIf Asc($iPosition) + 47 <= 126 And Asc($iPosition) > 32 And Asc($iPosition) < 127 Then $sReturn &= Chr(Asc($iPosition) + 47) Else $sReturn &= $iPosition EndIf Next Return $sReturn EndFunc ;==>_Rot47 UDF List:  _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
FireFox Posted October 3, 2012 Share Posted October 3, 2012 (edited) Retreives the system tray icon index according to its tooltip text :expandcollapse popup#include <GuiToolBar.au3> #region EXAMPLE Global $sToolTipTitle = "pause me !" TraySetToolTip($sToolTipTitle) Global $aSystray_ButtonData = Systray_GetIconIndex($sToolTipTitle) If $aSystray_ButtonData = 0 Then MsgBox(16, "Error code " & @error, "Icon not found in system tray") Else _GUICtrlToolbar_ClickButton($aSystray_ButtonData[0], $aSystray_ButtonData[1], "right") EndIf #endregion EXAMPLE ; #FUNCTION# ==================================================================================================================== ; Name...........: Systray_GetIconIndex ; Description ...: Retreives the system tray icon index according to its tooltip text ; Syntax.........: Systray_GetIconIndex($sSystrayGetIconIndex_ToolTipTitle, $blSystrayGetIconIndex_ExpandSystray = True) ; Parameters ....: $sSystrayGetIconIndex_ToolTipTitle - Tooltip text ; $blSystrayGetIconIndex_ExpandSystray - Expand state: ; | True - If the icon belongs to the overflow wnd, this last will be showed ; | False - Do not show the overflow wnd when the icon belongs to it ; Return values .: Success - Array containing the control handle and the button index ; Failure - 0, sets @error: ; |1 - Icon not found ; |2 - System tray control not found ; |3 - No icons found in the system tray ; Author ........: FireFox (d3mon) ; Modified.......: ; Remarks .......: ; Related .......: ; Link ..........: ; Example .......: Yes ; =============================================================================================================================== Func Systray_GetIconIndex($sSystrayGetIconIndex_ToolTipTitle, $blSystrayGetIconIndex_ExpandSystray = True) Local $aSystrayGetIconIndex_CtrlCLASS[2] = ["Shell_TrayWnd", "NotifyIconOverflowWindow"], $aSystrayGetIconIndex_ReturnData[2] Local $iSystrayGetIconIndex_CtrlCount = 1, $hSystrayGetIconIndex_CtrlHandle, $iSystrayGetIconIndex_ButtonCount Switch @OSVersion Case "WIN_VISTA", "WIN_7", "WIN_8" $iSystrayGetIconIndex_CtrlCount = 2 EndSwitch For $iSystrayGetIconIndex_CtrlIndex = 0 To $iSystrayGetIconIndex_CtrlCount - 1 $hSystrayGetIconIndex_CtrlHandle = ControlGetHandle("[Class:" & $aSystrayGetIconIndex_CtrlCLASS[$iSystrayGetIconIndex_CtrlIndex] & "]", "", "[Class:ToolbarWindow32;Instance:1]") If @error Then Return SetError(2, 0, 0) EndIf $iSystrayGetIconIndex_ButtonCount = _GUICtrlToolbar_ButtonCount($hSystrayGetIconIndex_CtrlHandle) If $iSystrayGetIconIndex_ButtonCount = 0 Then Return SetError(3, 0, 0) EndIf For $iSystrayGetIconIndex_ButtonIndex = 0 To $iSystrayGetIconIndex_ButtonCount - 1 ;~ ConsoleWrite(_GUICtrlToolbar_GetButtonText($hSystrayGetIconIndex_CtrlHandle, $iSystrayGetIconIndex_ButtonIndex) & @CRLF) If _GUICtrlToolbar_GetButtonText($hSystrayGetIconIndex_CtrlHandle, $iSystrayGetIconIndex_ButtonIndex) = $sSystrayGetIconIndex_ToolTipTitle Then If $iSystrayGetIconIndex_CtrlIndex = 1 And $blSystrayGetIconIndex_ExpandSystray Then ControlClick("[CLASS:" & $aSystrayGetIconIndex_CtrlCLASS[0] & "]", "", "[CLASS:Button; INSTANCE:1]", "left") EndIf $aSystrayGetIconIndex_ReturnData[0] = $hSystrayGetIconIndex_CtrlHandle $aSystrayGetIconIndex_ReturnData[1] = $iSystrayGetIconIndex_ButtonIndex Return $aSystrayGetIconIndex_ReturnData EndIf Next Next Return SetError(1, 0, 0) EndFunc ;==>Systray_GetIconIndex Edited August 20, 2013 by FireFox Link to comment Share on other sites More sharing options...
FireFox Posted October 4, 2012 Share Posted October 4, 2012 (edited) Intercepts the "End task" event of the taskmanager by the WM_CLOSE message : #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Opt("GUIOnEventMode", 1) #region GUI $GUI = GUICreate("GUI") GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit") GUICtrlCreateLabel("You can use me as a normal GUI, except that I intercept the WM_CLOSE message," & _ " which is also sent by the taskmanager when you press the ""End task"" button (not the ""End process"" one).", 10, 10, 380, 40) GUIRegisterMsg($WM_CLOSE, "WM_CLOSE") GUISetState() #endregion GUI While 1 Sleep(1000) WEnd Func WM_CLOSE($hWnd, $iMsg, $wParam, $lParam) ;do your last actions here before the script exits MsgBox(48, "Warning", "The taskmanager wants to kill me !" & @CRLF & "Press OK to exit", 0, $GUI) ;if you let the MsgBox showed for few seconds, the taskmanager will see that the script is hanging and will suggest you to kill the script Return $GUI_RUNDEFMSG EndFunc ;==>WM_CLOSE Func _Exit() Exit EndFunc ;==>_Exit Edited October 4, 2012 by FireFox Link to comment Share on other sites More sharing options...
notechkid Posted October 4, 2012 Share Posted October 4, 2012 Calculate the bit entropy of a password. The higher the bit entropy, the harder it is to guess/bruteforce the password. expandcollapse popup#cs _CalculateBitEntropy Name: _CalculateBitEntropy Description: Calculate the bit entropy of a string. Author: dany Parameters: $sStr - String: String to evaluate. $fCase - Boolean: Do case-sensitive evaluation, default true. Return values: Success: - Float: Bit entropy. Failure: - 0 and sets @error Link: http://en.wikipedia.org/wiki/Password_strength#Entropy_as_a_measure_of_password_strength #ce Func _CalculateBitEntropy($sStr, $fCase = True) If IsBinary($sStr) Then $sStr = BinaryToString($sStr) If Not IsString($sStr) Then Return SetError(1, 0, 0) Local $aDice, $iH = 0, $iLen = StringLen($sStr) If 0 = $iLen Then Return SetError(2, 0, 0) $aDice = StringSplit($sStr, ' ') If 1 < $aDice[0] Then Return $aDice[0] * 12.925 If StringIsDigit($sStr) Then $iH = 3.3219 ElseIf StringIsXDigit($sStr) Then $iH = 4.0000 ElseIf StringIsAlpha($sStr) Then $iH = 4.7004 If $fCase Then If StringRegExp($sStr, '[a-z]+') And StringRegExp($sStr, '[A-Z]+') Then $iH = 5.7004 EndIf ElseIf StringIsAlNum($sStr) Then $iH = 5.1699 If $fCase Then If StringRegExp($sStr, '[a-z]+') And StringRegExp($sStr, '[A-Z]+') Then $iH = 5.9542 EndIf ElseIf StringRegExp($sStr, '^[^[:cntrl:]x7F]+$') Then $iH = 6.5699 ElseIf _StringRegExp($sStr, '^[^[:cntrl:]x7Fx81x8Dx8Fx90x9D]+$') Then $iH = 7.7682 EndIf Return $iH * $iLen EndFunc Example: #include <CalculateBitEntropy.au3> Local $sPassA = 'Tr0ub4dor&3' ; Passphrase. Local $sPassB = 'correct horse battery staple' MsgBox(0, '_CalculateBitEntropy', $sPassA & ': ' & _CalculateBitEntropy($sPassA) & @CRLF & $sPassB & ': ' & _CalculateBitEntropy($sPassB)) Hate to say it, but this function is not correct. Right at the start of the function is a test for the number of words in the string (i.e. is it a password or passphrase). If a space is found in the string, then it is assumed that the string consists of a number of Diceware words. This assumption cannot be made. Let the program compare between the password 'Tr0ub4dor&3' and the passphrase 'Tr0ub4dor&3 Tr0ub4dor&3'. It will tell you the latter is the weakest, which it is clearly not. Not every string containing spaces is a list of Diceware words. It should at least be tested if the words are alphanumeric (without special characters). So there are two things to improve: (1) decide if the words are 'plain' words, not containing any ampersands etc., and (2) decide if they are indeed from the limited Diceware word list that contains a mere 7776 words. Link to comment Share on other sites More sharing options...
dany Posted October 5, 2012 Share Posted October 5, 2012 (edited) Hate to say it, but this function is not correct. Right at the start of the function is a test for the number of words in the string (i.e. is it a password or passphrase). If a space is found in the string, then it is assumed that the string consists of a number of Diceware words. This assumption cannot be made. Let the program compare between the password 'Tr0ub4dor&3' and the passphrase 'Tr0ub4dor&3 Tr0ub4dor&3'. It will tell you the latter is the weakest, which it is clearly not. Not every string containing spaces is a list of Diceware words. It should at least be tested if the words are alphanumeric (without special characters). So there are two things to improve: (1) decide if the words are 'plain' words, not containing any ampersands etc., and (2) decide if they are indeed from the limited Diceware word list that contains a mere 7776 words. You are correct. True Diceware passphrases arn't distinguished from random gibberish containing spaces. Suggested improvement 1 (checking alphanumeric and space) is easily implemented: expandcollapse popup#cs _CalculateBitEntropy Name: _CalculateBitEntropy Description: Calculate the bit entropy of a string. Author: dany Parameters: $sStr - String: String to evaluate. $fCase - Boolean: Do case-sensitive evaluation, default true. Return values: Success: - Float: Bit entropy. Failure: - 0 and sets @error Link: http://en.wikipedia.org/wiki/Password_strength#Entropy_as_a_measure_of_password_strength #ce Func _CalculateBitEntropy($sStr, $fCase = True) If IsBinary($sStr) Then $sStr = BinaryToString($sStr) If Not IsString($sStr) Then Return SetError(1, 0, 0) Local $aDice, $iH = 0, $iLen = StringLen($sStr) If 0 = $iLen Then Return SetError(2, 0, 0) $aDice = StringSplit($sStr, ' ') If 1 < $aDice[0] And StringRegExp($sStr, '^[[:alnum:] ]+$') Then Return $aDice[0] * 12.925 If StringIsDigit($sStr) Then $iH = 3.3219 ElseIf StringIsXDigit($sStr) Then $iH = 4.0000 ElseIf StringIsAlpha($sStr) Then $iH = 4.7004 If $fCase Then If StringRegExp($sStr, '[[:lower:]]') And StringRegExp($sStr, '[[:upper:]]') Then $iH = 5.7004 EndIf ElseIf StringIsAlNum($sStr) Then $iH = 5.1699 If $fCase Then If StringRegExp($sStr, '[[:lower:]]') And StringRegExp($sStr, '[[:upper:]]') Then $iH = 5.9542 EndIf ElseIf StringRegExp($sStr, '^[^[:cntrl:]x7F]+$') Then $iH = 6.5699 ElseIf StringRegExp($sStr, '^[^[:cntrl:]x7Fx81x8Dx8Fx90x9D]+$') Then $iH = 7.7682 EndIf Return $iH * $iLen EndFunc However, I'm not going to implement a check if the words are in a Diceware list, as there is no standard list. Besides this function only calculates bit entropy, it doesn't care about the validity of the words that's the job of a login script. Thanks for the feedback edit: optimized regepx. edit 2: corrected typo in code... Edited December 6, 2012 by dany [center]Spiderskank Spiderskank[/center]GetOpt Parse command line options UDF | AU3Text Program internationalization UDF | Identicon visual hash UDF Link to comment Share on other sites More sharing options...
JScript Posted October 7, 2012 Share Posted October 7, 2012 expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> _Example() Func _Example() Local $hForm, $iInput $Form1 = GUICreate("Input control with [Enter] key!", 320, 240, -1, -1) $iInput = _GUICtrlCreateInputEx("Type [Enter] key to see the effect!", 14, 100, 290, 23) GUICtrlCreateButton("Button", 105, 165, 100) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $iInput MsgBox(4096, "Read!", GUICtrlRead($iInput)) EndSwitch WEnd EndFunc ;==>_Example Func _GUICtrlCreateInputEx($sText, $iLeft, $iTop, $iWidth = -1, $iHeight = -1, $iStyle = -1, $iExStyle = -1) Local $iCtrlID $iCtrlID = GUICtrlCreateInput($sText, $iLeft, $iTop, $iWidth, $iHeight, $iStyle, $iExStyle) ; To [Enter] key effect! Local $aAccelKeys[1][2] = [["{ENTER}", $iCtrlID]] GUISetAccelerators($aAccelKeys) ;--- Return $iCtrlID EndFunc JS http://forum.autoitbrasil.com/ (AutoIt v3 Brazil!!!) Somewhere Out ThereJames Ingram Download Dropbox - Simplify your life!Your virtual HD wherever you go, anywhere! Link to comment Share on other sites More sharing options...
funkey Posted October 8, 2012 Share Posted October 8, 2012 expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> _Example() Func _Example() Local $hForm, $iInput $Form1 = GUICreate("Input control with [Enter] key!", 320, 240, -1, -1) $iInput = _GUICtrlCreateInputEx("Type [Enter] key to see the effect!", 14, 100, 290, 23) GUICtrlCreateButton("Button", 105, 165, 100) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $iInput MsgBox(4096, "Read!", GUICtrlRead($iInput)) EndSwitch WEnd EndFunc ;==>_Example Func _GUICtrlCreateInputEx($sText, $iLeft, $iTop, $iWidth = -1, $iHeight = -1, $iStyle = -1, $iExStyle = -1) Local $iCtrlID $iCtrlID = GUICtrlCreateInput($sText, $iLeft, $iTop, $iWidth, $iHeight, $iStyle, $iExStyle) ; To [Enter] key effect! Local $aAccelKeys[1][2] = [["{ENTER}", $iCtrlID]] GUISetAccelerators($aAccelKeys) ;--- Return $iCtrlID EndFunc JS Nice, but only works right with one input control. Programming today is a race between software engineers striving tobuild bigger and better idiot-proof programs, and the Universetrying to produce bigger and better idiots.So far, the Universe is winning. Link to comment Share on other sites More sharing options...
AZJIO Posted October 9, 2012 Share Posted October 9, 2012 (edited) #include <GUIConstantsEx.au3> _Example() Func _Example() Local $Form1, $iDummy, $iInput1, $iInput2, $iInput3, $iInput4, $nMsg $Form1 = GUICreate("Input control with [Enter] key!", 320, 240, -1, -1) $iInput1 = GUICtrlCreateInput("Input1", 14, 10, 290, 23) $iInput2 = GUICtrlCreateInput("Input2", 14, 40, 290, 23) $iInput3 = GUICtrlCreateInput("Input3", 14, 70, 290, 23) $iInput4 = GUICtrlCreateInput("Input4", 14, 100, 290, 23) $iDummy = GUICtrlCreateDummy() Local $aAccelKeys[1][2] = [["{ENTER}", $iDummy]] GUISetAccelerators($aAccelKeys) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $iDummy Switch ControlGetFocus($Form1) Case 'Edit1' MsgBox(4096, "Read!", GUICtrlRead($iInput1)) Case 'Edit2', 'Edit3', 'Edit4' MsgBox(4096, "Read!", GUICtrlRead($iInput2) & @CRLF & GUICtrlRead($iInput3) & @CRLF & GUICtrlRead($iInput4)) ; Case 'SysListView321' ; _Open() ; etc EndSwitch EndSwitch WEnd EndFunc ;==>_Example Edited September 18, 2013 by AZJIO My other projects or all Link to comment Share on other sites More sharing options...
dany Posted October 9, 2012 Share Posted October 9, 2012 Three little functions to calculate the contrast between two colors (RGB or ARGB values). _Color_ColorDifference (with 2 small helpers): expandcollapse popup#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w- 7 ConsoleWrite('Color difference: ' & _Color_ColorDifference(0xFF000000, 0xFFFFFFFF) & @CRLF) ; Black and white: 765 or maximum contrast. ConsoleWrite('Color difference: ' & _Color_ColorDifference(0xFF54123D, 0xFF134253) & @CRLF) ; 135, not so good. ; #FUNCTION# =================================================================== ; Name ..........: _Color_ColorDifference ; Description ...: Calculate difference between two colors. ; Syntax ........: _Color_ColorDifference($vARGB1, $vARGB2) ; Parameters ....: $vARGB1 - Variant: A Hex, Integer or Binary color value. ; $vARGB2 - Variant: A Hex, Integer or Binary color value. ; Return values .: Success - Int: Color difference. ; Failure - Int: Returns 0 and sets @error: ; |1 First parameter isn't a Hex string. ; |2 Second parameter isn't a Hex string. ; Author ........: dany ; Modified ......: ; Remarks .......: A value of 500 or higher is recommended for good contrast. ; Link ..........: http://www.w3.org/TR/2000/WD-AERT-20000426#color-contrast ; ============================================================================== Func _Color_ColorDifference($vARGB1, $vARGB2) If IsInt($vARGB1) Or IsBinary($vARGB1) Then $vARGB1 = Hex($vARGB1) If IsInt($vARGB2) Or IsBinary($vARGB1) Then $vARGB2 = Hex($vARGB2) If Not StringIsXDigit($vARGB1) Then Return SetError(1, 0, 0) If Not StringIsXDigit($vARGB2) Then Return SetError(2, 0, 0) If 7 > StringLen($vARGB1) Then $vARGB1 = 'FF' & $vARGB1 If 7 > StringLen($vARGB2) Then $vARGB1 = 'FF' & $vARGB2 Local $iRed, $iGreen, $iBlue, $iColor1, $iColor2 $iColor1 = Dec(StringMid($vARGB1, 3, 2)) $iColor2 = Dec(StringMid($vARGB2, 3, 2)) $iRed = __Color_Max($iColor1, $iColor2) - __Color_Min($iColor1, $iColor2) $iColor1 = Dec(StringMid($vARGB1, 5, 2)) $iColor2 = Dec(StringMid($vARGB2, 5, 2)) $iGreen = __Color_Max($iColor1, $iColor2) - __Color_Min($iColor1, $iColor2) $iColor1 = Dec(StringMid($vARGB1, 7, 2)) $iColor2 = Dec(StringMid($vARGB2, 7, 2)) $iBlue = __Color_Max($iColor1, $iColor2) - __Color_Min($iColor1, $iColor2) Return $iRed + $iGreen + $iBlue EndFunc ;==>_Color_ColorDifference ; #INTERNAL_USE_ONLY# ========================================================== ; Name ..........: __Color_Min ; Description ...: Return lowest of two values. ; Remarks .......: For Internal Use Only. ; ============================================================================== Func __Color_Min($iX, $iY) If Number($iX) > Number($iY) Then Return $iY Return $iX EndFunc ;==>__Color_Min ; #INTERNAL_USE_ONLY# ========================================================== ; Name ..........: __Color_Max ; Description ...: Return highest of two values. ; Remarks .......: For Internal Use Only. ; ============================================================================== Func __Color_Max($iX, $iY) If Number($iX) < Number($iY) Then Return $iY Return $iX EndFunc ;==>__Color_Max _Color_BrightnessDifference: expandcollapse popup#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w- 7 ConsoleWrite('Brightness difference: ' & _Color_BrightnessDifference(0xFF000000, 0xFFFFFFFF) & @CRLF) ; Black and white: 255 or maximum contrast. ConsoleWrite('Brightness difference: ' & _Color_BrightnessDifference(0xFF54123D, 0xFF134253) & @CRLF) ; 11.249, not so good. ; #FUNCTION# =================================================================== ; Name ..........: _Color_BrightnessDifference ; Description ...: Calculate brightness difference between two colors. ; Syntax ........: _Color_BrightnessDifference($vARGB1, $vARGB2) ; Parameters ....: $vARGB1 - Variant: A Hex, Integer or Binary color value. ; $vARGB2 - Variant: A Hex, Integer or Binary color value. ; Return values .: Success - Float: Brightness difference. ; Failure - Int: Returns 0 and sets @error: ; |1 First parameter isn't a Hex string. ; |2 Second parameter isn't a Hex string. ; Author ........: dany ; Modified ......: ; Remarks .......: A value of 125 or higher is recommended for good contrast. ; Link ..........: http://www.w3.org/TR/2000/WD-AERT-20000426#color-contrast ; ============================================================================== Func _Color_BrightnessDifference($vARGB1, $vARGB2) If IsInt($vARGB1) Or IsBinary($vARGB1) Then $vARGB1 = Hex($vARGB1) If IsInt($vARGB2) Or IsBinary($vARGB1) Then $vARGB2 = Hex($vARGB2) If Not StringIsXDigit($vARGB1) Then Return SetError(1, 0, 0) If Not StringIsXDigit($vARGB2) Then Return SetError(2, 0, 0) If 7 > StringLen($vARGB1) Then $vARGB1 = 'FF' & $vARGB1 If 7 > StringLen($vARGB2) Then $vARGB1 = 'FF' & $vARGB2 Local $iRed, $iGreen, $iBlue, $iBrightness1, $iBrightness2 $iRed = Dec(StringMid($vARGB1, 3, 2)) $iGreen = Dec(StringMid($vARGB1, 5, 2)) $iBlue = Dec(StringMid($vARGB1, 7, 2)) $iBrightness1 = ((299 * $iRed) + (587 * $iGreen) + (114 * $iBlue)) / 1000; $iRed = Dec(StringMid($vARGB2, 3, 2)) $iGreen = Dec(StringMid($vARGB2, 5, 2)) $iBlue = Dec(StringMid($vARGB2, 7, 2)) $iBrightness2 = ((299 * $iRed) + (587 * $iGreen) + (114 * $iBlue)) / 1000; Return Abs($iBrightness1 - $iBrightness2) EndFunc ;==>_Color_BrightnessDifference _Color_ColorDifference and _Color_BrightnessDifference should be used side-by-side to get the most reliable results. _Color_LuminosityRatio: expandcollapse popup#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w- 7 ConsoleWrite('Luminosity ratio: ' & _Color_LuminosityRatio(0xFF000000, 0xFFFFFFFF) & @CRLF) ; Black and white: 21 or maximum contrast. ConsoleWrite('Luminosity ratio: ' & _Color_LuminosityRatio(0xFF54123D, 0xFF134253) & @CRLF) ; 1.267382, not so good. ; #FUNCTION# =================================================================== ; Name ..........: _Color_LuminosityRatio ; Description ...: Calculate luminosity ratio between two colors. ; Syntax ........: _Color_LuminosityRatio($vARGB1, $vARGB2) ; Parameters ....: $vARGB1 - Variant: A Hex, Integer or Binary color value. ; $vARGB2 - Variant: A Hex, Integer or Binary color value. ; Return values .: Success - Float: Luminosity ratio. ; Failure - Int: Returns 0 and sets @error: ; |1 First parameter isn't a Hex string. ; |2 Second parameter isn't a Hex string. ; Author ........: dany ; Modified ......: ; Remarks .......: A value of 5 or higher is recommended for good contrast. ; Link ..........: http://www.w3.org/TR/2006/WD-WCAG20-20060427/appendixA.html#luminosity-contrastdef ; ============================================================================== Func _Color_LuminosityRatio($vARGB1, $vARGB2) If IsInt($vARGB1) Or IsBinary($vARGB1) Then $vARGB1 = Hex($vARGB1) If IsInt($vARGB2) Or IsBinary($vARGB1) Then $vARGB2 = Hex($vARGB2) If Not StringIsXDigit($vARGB1) Then Return SetError(1, 0, 0) If Not StringIsXDigit($vARGB2) Then Return SetError(2, 0, 0) If 7 > StringLen($vARGB1) Then $vARGB1 = 'FF' & $vARGB1 If 7 > StringLen($vARGB2) Then $vARGB1 = 'FF' & $vARGB2 Local $iRed, $iGreen, $iBlue, $iLum1, $iLum2 $iRed = 0.2126 * ((Dec(StringMid($vARGB1, 3, 2)) / 255) ^ 2.2) $iGreen = 0.7152 * ((Dec(StringMid($vARGB1, 5, 2)) / 255) ^ 2.2) $iBlue = 0.0722 * ((Dec(StringMid($vARGB1, 7, 2)) / 255) ^ 2.2) $iLum1 = $iRed + $iGreen + $iBlue $iRed = 0.2126 * ((Dec(StringMid($vARGB2, 3, 2)) / 255) ^ 2.2) $iGreen = 0.7152 * ((Dec(StringMid($vARGB2, 5, 2)) / 255) ^ 2.2) $iBlue = 0.0722 * ((Dec(StringMid($vARGB2, 7, 2)) / 255) ^ 2.2) $iLum2 = $iRed + $iGreen + $iBlue If $iLum1 > $iLum2 Then Return ($iLum1 + 0.05) / ($iLum2 + 0.05) Else Return ($iLum2 + 0.05) / ($iLum1 + 0.05) EndIf EndFunc ;==>_Color_LuminosityRatio [center]Spiderskank Spiderskank[/center]GetOpt Parse command line options UDF | AU3Text Program internationalization UDF | Identicon visual hash UDF Link to comment Share on other sites More sharing options...
guinness Posted October 14, 2012 Share Posted October 14, 2012 - Check if a string is a palindrome. UDF List:  _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 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