PAULOGARCIA2005 Posted April 25, 2010 Share Posted April 25, 2010 (edited) Well, this is my first UDF, IT IS NOT COMPLETE.If anyone wants to help would be great.Anything (bugs, corrections, etc) please tell me.Functions:_Captcha_Create_Captcha_SaveToFile [Working on|Very SOON]_Captcha_Delete [sOON]Images:From CaptchaExample.au3.EmbeddedScript:CaptchaUDF.au3expandcollapse popup#include <GDIPlus.au3> ; #FUNCTION# ;=============================================================================== ; ; Name...........: _Captcha_Create ; Description ...: Create a captcha ; Syntax.........: _Captcha_Create($hWnd, $nX, $nY, $opt=0, $iNC = 5, $lines = 1, $optc = 2, $colorsT = 3, $colorsL = 4, $sFront = "Times New Roman") ; Parameters ....: ; $hWnd - The Window handle of the GUI in which the message appears. ; $nX - X coordinate where the captcha will be drawn. ; $nY - Y coordinate where the captcha will be drawn. ; $opt - (Optional) General options. See below: ; |0 = (Default) uppercase characters, ; |1 = lowercase characters, ; |2 = uppercase and lowercase characters, ; |3 = numbers, ; |4 = uppercase, lowercase and numbers. ; $iNC - (Optional) Number of characters (5 by Default). ; $lines - (Optional) See below: ; |False or 0 = Don't draw lines (NOT RECOMENDED, Very easy to an OCR), ; |True or 1 = (Default) Draw lines. ; $optc - (Optional) Color options. See below: ; |0 = Same color for Text and Lines; ; |1 = (Default) Diferent color for Text and Lines; ; |2 = Personalized text color (use $colorsT) ; |3 = Personalized line color (use $colorsL) ; |4 = Personalized text and line colors (use $colorsT and $colorsL) ; $colorsT - (Optional) Number of colors acepted (Text). See Below: ; |0 = Black, ; |1 = Red, ; |2 = Red and Green, ; |3 = (Default) Red, Green and Blue, ; |4 = Red, Green, Blue and Yellow. ; | If you use $optc parameter with 2 or 4, you can use here a personalized color in ARGB (a.k.a. RGBA) format like 0xFFC0C0C0 (Silver). ; $colorsL - (Optional) Number of colors acepted (Lines). See Below: ; |0 = Black, ; |1 = Red, ; |2 = Red and Green, ; |3 = Red, Green and Blue, ; |4 = (Default) Red, Green, Blue and Yellow. ; | If you use $optc parameter with 3 or 4, you can use here a personalized color in ARGB (a.k.a. RGBA) format like 0xFFC0C0C0 (Silver). ; $sFront - (Optional) The front to be used (Times New Roman by Default). ; ; Return values .: ; Success: A string with the captcha's characters. ; Failure: Nothing and @error is set to 1 ; ; Author ........: PAULOGARCIA2005 ; Modified.......: ; Remarks .......: If you use $optc parameter with 0, and diferent values in $colorsT and $colorsL, the lowest value from $colorsT and $colorsL is taken. ; Related .......: ; Link ..........: http://www.autoitscript.com/forum/index.php?showtopic=113563 ; Example .......: Yes ; ; ;========================================================================================== Func _Captcha_Create($hWnd, $nX, $nY, $opt=0, $iNC = 5, $lines = True, $optc = 1, $colorsT = 3, $colorsL = 4, $sFront = "Times New Roman") Local $hGUI, $hGraphic, $array, $aPoints[4][2] Local $color[5] = [0xFF000000, 0xB0FF0000, 0xB0008000, 0xB00000FF, 0xB0FFFF00] Local $arrayMa = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" Local $arraym = "abcdefghijklmnopqrstuvwxyz" Local $arrayN = "0123456789" If $opt = 0 Then Local $array = StringSplit ($arrayMa, "") ElseIf $opt = 1 Then Local $array = StringSplit ($arraym, "") ElseIf $opt = 2 Then Local $array = StringSplit ($arrayMa&$arraym, "") ElseIf $opt = 3 Then Local $array = StringSplit ($arrayN, "") ElseIf $opt = 4 Then Local $array = StringSplit ($arrayMa&$arraym&$arrayN, "") EndIf Local $stringlast Local $sp = $nX Local $string = "" If $optc = 0 Then If $colorsT = $colorsL Then $max = Random(1,$colorsT,1) If $colorsT < $colorsL Then $max = Random(1,$colorsT,1) If $colorsL < $colorsT Then $max = Random(1,$colorsL,1) If $colorsL = 0 Or $colorsT = 0 Then $max = 0 $cTxt = $color[$max] $cLin = $cTxT ElseIf $optc = 1 Then $cTxt = $color[Random(1,$colorsT,1)] If $colorsT = 0 Then $cTxt = $color[0] $cLin = $color[Random(1,$colorsL,1)] If $colorsL = 0 Then $cLin = $color[0] ElseIf $optc = 2 Then $cTxt = $colorsT ElseIf $optc = 3 Then $cLin = $colorsL ElseIf $optc = 4 Then $cTxt = $colorsT $cLin = $colorsL EndIf ; Draw the string _GDIPlus_Startup () $hGraphic = _GDIPlus_GraphicsCreateFromHWND ($hWnd) $hBrush = _GDIPlus_BrushCreateSolid ($cTxt) $hFormat = _GDIPlus_StringFormatCreate () $hFamily = _GDIPlus_FontFamilyCreate ($sFront) For $i = 1 to $iNC $tLayout = _GDIPlus_RectFCreate ($sp, $nY, 0, 0) $hFont = _GDIPlus_FontCreate ($hFamily, Random(10,15)) $stringlast = $array[Random (1, UBound ($array))] $aInfo = _GDIPlus_GraphicsMeasureString ($hGraphic, $stringlast, $hFont, $tLayout, $hFormat) _GDIPlus_GraphicsDrawStringEx ($hGraphic, $stringlast, $hFont, $aInfo[0], $hFormat, $hBrush) $string &= $stringlast If $stringlast = 'W' Then $sp = $sp+2 _GDIPlus_FontDispose ($hFont) $sp = $sp+14 Next _GDIPlus_FontFamilyDispose ($hFamily) _GDIPlus_StringFormatDispose ($hFormat) _GDIPlus_BrushDispose ($hBrush) ; Draw some lines If $lines = True Then $PenC = _GDIPlus_PenCreate($cLin, 2) _GDIPlus_GraphicsDrawLine ($hGraphic, Random($nX, $nX+5), Random($nY+4,$nY+16), Random($nX+8, $nX+$sp), Random($nY+4,$nY+16), $PenC) _GDIPlus_GraphicsDrawLine ($hGraphic, Random($nX+($sp/Random(2,3,1)), $nX+($sp-($sp/2))), Random($nY+6,$nY+14), Random($nX+($sp/2), $nX+$sp), Random($nY+6,$nY+16), $PenC) EndIf ; Clean up resources _GDIPlus_PenDispose($PenC) _GDIPlus_GraphicsDispose ($hGraphic) _GDIPlus_Shutdown () Return $string EndFunc ;==>_Captcha_CreateExample:CaptchaExample.au3#include <GDIPlus.au3> #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <CaptchaUDF.au3> ; <== Here is CaptchaUDF #Region ### GUI (Koda) $hGUI = GUICreate("Captcha", 401, 131) $Graphic1 = GUICtrlCreateGraphic(160, 30, 80, 20) GUICtrlSetBkColor(-1, 0xFFFFFF) $Input1 = GUICtrlCreateInput("", 154, 66, 97, 21, BitOR($ES_CENTER,$ES_AUTOHSCROLL)) $Button1 = GUICtrlCreateButton("Go", 162, 96, 85, 25, 0) $Label1 = GUICtrlCreateLabel("Type the characters you see in the picture:", 0, 0, 206, 17, $SS_CENTERIMAGE) GUISetState(@SW_SHOW) #EndRegion ### $captcha = _Captcha_Create($hGUI, 0, 0, 4) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 If StringCompare(GUICtrlRead($Input1), $captcha, 2) = 0 Then ;Use 1 if the recognition should be case sensitive. MsgBox(64, "Captcha", "OK") Exit Else MsgBox(16, "Captcha", "NO") EndIf EndSwitch WEndSorry for my bad english. Edited May 11, 2010 by PAULOGARCIA2005 Link to comment Share on other sites More sharing options...
trancexx Posted April 25, 2010 Share Posted April 25, 2010 I like the approach. ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
MrCreatoR Posted April 25, 2010 Share Posted April 25, 2010 (edited) *Click* Edited April 25, 2010 by MrCreatoR Spoiler Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1 AutoIt Russian Community My Work... Spoiler Projects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize ProgramUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF Examples: ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating ) * === My topics === * ================================================== ================================================== AutoIt is simple, subtle, elegant. © AutoIt Team Link to comment Share on other sites More sharing options...
PAULOGARCIA2005 Posted April 25, 2010 Author Share Posted April 25, 2010 *Click* .All the aproachs are excelents, I only tried to do something diferent, and this script isn't finished. Link to comment Share on other sites More sharing options...
AlmarM Posted April 26, 2010 Share Posted April 26, 2010 Eh.. It disappears when I minimize it. Minesweeper A minesweeper game created in autoit, source available. _Mouse_UDF An UDF for registering functions to mouse events, made in pure autoit. 2D Hitbox Editor A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes. 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