Jump to content

flet

Active Members
  • Posts

    20
  • Joined

  • Last visited

Everything posted by flet

  1. you're probably right.. btw, i meant ugliness in the sense: mixing onevent and message-loop in 1 script really hurts my eyes, but after spending a couple of hours on this problem i'm going for ugly now. user won't see a thing of it when my script is compiled to exe
  2. Thanks for your input Melba. I'm going to try it like you're suggesting in my actual script: a few adjustments are needed though. Quick question: Do I check for the flag thingy in the 'While 1'-loop from the main GUI? cause creating an extra while loop in a child gui will freeze the script... It's a dilemma: plain ugliness OR melting my brains trying to solve everything OnEvent for the sake of consistency If your suggestion doesn't work I'm tempted to do it in a message-loop..I've alreay put enough time into this
  3. Is there a way to create a GUI in a for-loop? As in: I have a program which asks the user for passwords if the email is unknown. For each account that is not known, I want a GUI to be created that prompts the user for the password. After user clicks the 'OK' button on the GUI, the password is written to a file, and program continues with the next account. Something like this (I AM aware that code below doesn't work): #include <GUIConstantsEx.au3> #include <ButtonConstants.au3> #include <WindowsConstants.au3> #include <EditConstants.au3> Opt("GUIOnEventMode", 1) Opt("MustDeclareVars", 1) Global $accounts_file = "accountz.ini" Global $gui_pw, $label_pw, $input_pw, $button_pw_enter Func _GUIAskPasswordButtonClick() Local $password = GUICtrlRead($input_pw) Switch @GUI_CtrlId Case $button_pw_enter If ($password <> "") Then IniWrite($accounts_file, GUICtrlRead($label_pw), "Password", $password) GUIDelete($gui_pw) Else MsgBox(16, "Error", "Please type password:") GUICtrlSetData($input_pw, "") GUICtrlSetState($input_pw, $GUI_FOCUS) EndIf EndSwitch EndFunc Func _Exit() Exit EndFunc Func GUIAskPassword($login) $gui_pw = GUICreate("Account unknown", 395, 180) GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit") GUICtrlCreateGroup("", 70, 50, 300, 80) GUICtrlCreateLabel("Login:", 85, 70, 75, 20) $label_pw = GUICtrlCreateLabel($login, 170, 70, 175, 20) GUICtrlCreateLabel("Password:", 85, 95, 75, 20) $input_pw = GUICtrlCreateInput("", 170, 95, 175, 20, $ES_PASSWORD) GUICtrlSetState(-1, $GUI_FOCUS) $button_pw_enter = GUICtrlCreateButton("&OK", 163, 145, 75, 25, $BS_DEFPUSHBUTTON) GUICtrlSetOnEvent(-1, "_GUIAskPasswordButtonClick") GUISetState(@SW_SHOW, $gui_pw) EndFunc Dim $accounts[3] = ["first@email.com", "second@email.com", "third@email.com"] For $i = 0 To Ubound($accounts) - 1 GUIAskPassword($accounts[$i]) Next While 1 Sleep(10) WEnd This piece of code is simplified. In my program this GUI is a child window and the number of accounts can vary. ONEVEnt mode is obligatory My script doesn't work because it puts all 3 GUI's in the same variable $gui_pw, so things are messed up big time: the first GUIs can't be closed. How do I wait until the user has clicked the OK button before creating the next GUI? Is there an easier and better way to do this? The only thing I came up with now, is to switch to messageloop mode and back to onevent mode after completing my function...but that is soooo ugly Any ideas?
  4. I've already read the wiki, but it's not clear to me how I can pause my ReallyLongFunc in an efficient way (without hotkeys or accelerators: button only). I am already able to interrupt the function by pressing the Stop-button or closing the gui. The sleep(100) statements was just for demonstrating purposes to keep things simple in this code snippet. It could have been other code, like logging in, writing to a file or various other things... What's the best way to pause? Checking after each line whether or not Pause has been pressed doesn't seem efficient to me. I need a few more pointers in the right direction, if you please
  5. Dear AutoIt community, I want to simulate the behaviour of the Start/Stop/Pause buttons in Winamp or any other Media Player, but I'm stuck with problem. Please consider my code below. Start, Stop and Pause all seem to function reasonably well. However, my long function can only be paused after each time $i is updated in the for-loop, and I want the program to be able to pause between all actions in that for-loop. Is this possible (without using Hotkeys or accelerator, and without using "If $pause_pressed Then" after each action)? What is the best practice here? I don't think my method is very efficient Thank you in advance, #include <GUIConstantsEx.au3> Opt("GUIOnEventMode", 1) Opt("MustDeclareVars", 1) ; Global variables Global $start_pressed = 0 Global $stop_pressed = 0 Global $pause_pressed = 0 Global $paused = 0 ; GUI Global $gui_main = GUICreate("Start/Stop/Pause", 230, 120) GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit") Global $label = GUICtrlCreateLabel("0", 10, 10, 250, 16) Global $button_start = GUICtrlCreateButton("&Start", 10, 31, 100) GUICtrlSetOnEvent($button_start, "_ButtonStart") Global $button_stop = GUICtrlCreateButtoN("S&top", 120, 31, 100) GUICtrlSetOnEvent($button_stop, "_ButtonStop") Global $button_pause = GUICtrlCreateButton("Pa&use", 10, 61, 100) GUICtrlSetOnEvent($button_pause, "_ButtonPause") GUISetState(@SW_SHOW, $gui_main) While 1 If $start_pressed Then $start_pressed = 0 ReallyLongFunc() EndIf Sleep(10) WEnd ; Control Events Func _Exit() Exit EndFunc Func _ButtonStart() $start_pressed = 1 ConsoleWrite("Start pressed" & @CRLF) EndFunc Func _ButtonStop() $stop_pressed = 1 ConsoleWrite("Stop pressed" & @CRLF) EndFunc Func _ButtonPause() $pause_pressed = 1 ConsoleWrite("Pause pressed" & @CRLF) EndFunc ; Rest of the functions: ReallyLongFunc has to be executed repeatedly until user is fed up with it and presses stop-button Func ReallyLongFunc() While 1 For $i = 1 To 50 If $start_pressed Then $start_pressed = 0 $stop_pressed = 0 $pause_pressed = 0 $i = 1 ElseIf $pause_pressed Then $pause_pressed = 0 Pause() ElseIf $stop_pressed Then $stop_pressed = 0 ExitLoop 2 EndIf GuiCtrlSetData($label, $i) ; lot of actions, here represented by these Sleep(100) statements. ; I'm wondering whether program can be paused between actions ; without checking "if ($pause_pressed)" after each line in this for-loop? Sleep(100) Sleep(100) Sleep(100) Sleep(100) Next WEnd EndFunc Func Pause() $paused = Not $paused If $paused Then GUICtrlSetData($button_pause, "Res&ume") Else GUICtrlSetData($button_pause, "Pa&use") EndIf While $paused If $pause_pressed Then ExitLoop Sleep(100) WEnd EndFunc
  6. http://www.autoitscript.com/wiki/Interrupting_a_running_function
  7. Your first If-statement is missing an EndIf. It should be: If Not MsgBox(1, "nothing", "can't see nothing", 10) Then PixelSearch( 472, 421, 484, 432, 0xbe3137, 10 ) EndIf
  8. Thanks guys. You're the best
  9. I have found two functions in different topics on this forum for converting an image to a 2d-array and for 2d-array back to an image again. However, when I convert the image stored in a 2d-array back to the real image, the colors have changed. I have been playing with: $aArray[$i][$j] = Hex(DllStructGetData($v_Buffer, 1), 6) and $aArray[$i][$j] = Hex(DllStructGetData($v_Buffer, 1), 8)(see code below), but to no avail. Is there someone who can help me (or explain to me where it goes wrong)? Is it because in the 1st function vBuffer works with dword and in the second with byte? #include <GDIPlus.au3> #include <Array.au3> #include <WinAPI.au3> Opt("MustDeclareVars", 1) _GDIPlus_Startup() Dim $pixelarray Local $file_in = "image1-before.jpg" Local $file_out = "image1-after.jpg" _FileImageToArray($file_in, $pixelarray) ; do some pixelpower stuff here... ;_ArrayDisplay($pixelarray) _FileArrayToImage($file_out, $pixelarray) _GDIPlus_Shutdown() ; code by Malkey: thanks man! Func _FileImageToArray($filename, ByRef $aArray) Local $Reslt, $stride, $format, $Scan0, $iW, $iH, $hImage Local $v_Buffer, $width, $height Local $i, $j $hImage = _GDIPlus_ImageLoadFromFile($filename) $iW = _GDIPlus_ImageGetWidth($hImage) $iH = _GDIPlus_ImageGetHeight($hImage) $Reslt = _GDIPlus_BitmapLockBits($hImage, 0, 0, $iW, $iH, $GDIP_ILMREAD, $GDIP_PXF32ARGB) ;Get the returned values of _GDIPlus_BitmapLockBits () $width = DllStructGetData($Reslt, "width") $height = DllStructGetData($Reslt, "height") $stride = DllStructGetData($Reslt, "stride") $format = DllStructGetData($Reslt, "format") $Scan0 = DllStructGetData($Reslt, "Scan0") Dim $aArray[$width][$height] For $i = 0 To $iW - 1 For $j = 0 To $iH - 1 $v_Buffer = DllStructCreate("dword", $Scan0 + ($j * $stride) + ($i * 4)) $aArray[$i][$j] = Hex(DllStructGetData($v_Buffer, 1), 8) Next Next _GDIPlus_BitmapUnlockBits($hImage, $Reslt) _GDIPlus_ImageDispose($hImage) Return EndFunc ;==>_FileImageToArray ; code by Malkey: thanks again ;) Func _FileArrayToImage($filename, $aArray) Local $iW = UBound($aArray, 1), $iH = UBound($aArray, 2), $sResult = "" Local $hBMP, $hImage1, $Reslt, $width, $height, $stride, $format, $Scan0 Local $sResult, $v_BufferA Local $i, $j $hBMP = _WinAPI_CreateBitmap($iW, $iH, 1, 32) $hImage1 = _GDIPlus_BitmapCreateFromHBITMAP($hBMP) $Reslt = _GDIPlus_BitmapLockBits($hImage1, 0, 0, $iW, $iH, $GDIP_ILMWRITE, $GDIP_PXF32ARGB) ;Get the returned values of _GDIPlus_BitmapLockBits () $width = DllStructGetData($Reslt, "width") $height = DllStructGetData($Reslt, "height") $stride = DllStructGetData($Reslt, "stride") $format = DllStructGetData($Reslt, "format") $Scan0 = DllStructGetData($Reslt, "Scan0") $v_BufferA = DllStructCreate("byte[" & $height * $width * 4 & "]", $Scan0) ;$AllPixels = DllStructGetData($v_BufferA, 1) For $j = 0 To $height - 1 For $i = 0 To $width - 1 $sResult &= Hex($aArray[$i][$j], 8) Next Next DllStructSetData($v_BufferA, 1, "0x" & StringStripWS($sResult, 8)) _GDIPlus_BitmapUnlockBits($hImage1, $Reslt) _GDIPlus_ImageSaveToFile($hImage1, $filename) _GDIPlus_ImageDispose($hImage1) _WinAPI_DeleteObject($hBMP) Return EndFunc ;==>_FileArrayToImage EDIT: Solved
  10. OK. Thanks for your quick replies. I'll try to rotate the selected carrot image then, and place it on top of the whole image. I think that that's my best option. I'll be back if I can't figure it out myself after viewing the examples in this forum. EDIT: Whoa that was fast Monoscout999! An example even before I finished writing my reply. Thanks man
  11. Hi. I'm trying to grasp the possibilities of GDI+, but I'm confused about some things. Maybe someone can explain and correct me where I'm wrong. What's the difference between an image, a graphic and a bitmap? What I understand is that an image is an image which can be vector-based or raster-based and that a bitmap is only raster-based. But where does a graphic fit in? In my script, which is solely for learning purposes, I'm trying to do the following: I have a bitmap picture which contains two cartoon carrots (see attachment), the left one positioned at an angle, like '/' , and the right one stands up straight, like '|' . Now I want to rotate the left one 25 degrees so it also stands up straight. But I can't figure out how to do this. This is what I have so far: #include <GDIPlus.au3> $image_in = "carrot.bmp" $image_out = "rotatedcarrot.bmp" _GDIPlus_Startup() $hImage = _GDIPlus_ImageLoadFromFile($image_in) ; rotated carrot is at: x-left: 4, y-top: 3, width: 15, height: 21 $hBitmap = _GDIPlus_BitmapCreateFromFile($image_in) $hSelection = _GDIPlus_BitmapCloneArea($hBitmap, 4, 3, 15, 21) ; save image to test if selection is correct _GDIPlus_ImageSaveToFile($hSelection, @ScriptDir & "\selectedcarrot.bmp") $hGraphic = _GDIPlus_ImageGetGraphicsContext($hSelection) ; trying to rotate here; selected carrot should rotate around its center $hMatrix = _GDIPlus_MatrixCreate() _GDIPlus_MatrixTranslate($hMatrix, Floor(15/2), Floor(21/2)) _GDIPlus_MatrixRotate($hMatrix, 25) _GDIPlus_GraphicsSetTransform($hGraphic, $hMatrix) _GDIPlus_GraphicsDrawImage($hGraphic, $hImage, 4, 3) ; save the image _GDIPlus_ImageSaveToFile($hImage, @ScriptDir & "\" & $image_out) ; clean up _GDIPlus_MatrixDispose($hMatrix) _GDIPlus_BitmapDispose($hBitmap) _GDIPlus_ImageDispose($hImage) _GDIPlus_GraphicsDispose($hGraphic) _GDIPlus_Shutdown() I don't need a GUI or something. Just working with the images will do. Who can enlighten me? Thanks in advance, - flet carrot.bmp
  12. Google for Tesseract. It's open source OCR software. When installed, you can OCR your screen capture like this: ShellExecuteWait(@ProgramFilesDir & "\tesseract-OCR\tesseract.exe", "inputimage.tif ocrresult") As you can see, it requires tif image as input and output file will be a textfile in the scriptdir
  13. I think you need the function _IELinkClickByText() $oIE = _IECreate("yourrurl") _IELinkClickByText ($oIE, "apple")
  14. Hi Gary IE.au3 in your include folder is perfect for this. Read the help file: it's very educational. The functions you are looking for all start with _IE.. To get you started (I have not tested the code): #include <IE.au3> ; Create a browser window $oIE = _IECreate ("yoururlhere") ; get pointers to the login form and username, password and signin fields $o_form = _IEFormGetObjByName($oIE, "formname") ; you can find the form name in the page source $o_login = _IEFormElementGetObjByName($o_form, "login") ; you can find the name of the input in the page source $o_password = _IEFormElementGetObjByName($o_form, "password") $o_signin = _IEFormElementGetObjByName($o_form, "submitbuttonname") ; you can find the name or id of the button in the page source $username = "your username here" $password = "your password here" ; Set field values and submit the form _IEFormElementSetValue ($o_login, $username) _IEFormElementSetValue ($o_password, $password) _IEAction ($o_signin, "click")
  15. Is there a way to find out how much my Internet Explorer window has scrolled down? In my script I'm trying to move my mouse to an advertisement that is near the bottom of the page (page length is different each time) to be able to make a screenshot of it or to right-click it -> save as. Downloading the image with InetGet($url, $filename) doesn't work here, because the image src is generated by a script that places a random ad and I usually don't get the same advertisement twice in a row. I'd like to use $object.scrollintoView for this, because it gets the ad perfectly into view, but if I want to move my mouse cursor to it I need to substract the amount scrolled down vertically from the y-coordinate of the advertisement image to move my mouse to it correctly. So I want to know how much I scrolled down vertically. Right now I'm using $oIE.document.parentwindow.scrollBy(0, $y-amount) but it's really gambling and hoping that the advertisement is in view. Can $oIE.document.body.scrollHeight or $oIE.document.body.clientHeight be of any use? I don't have much knowledge of MSDN or something. I found all these things via the search on this forum. I probably have to thank Dale Is there anyone who came across this problem earlier and has a solution for me or good pointers in the right direction? Thanks
  16. I wish to build a copy protection system for a piece of software that my friend and I wrote, preferably one that cannot be spoofed easily. Authentication via a server and dongles are not an option. Neither are serial keys. So I was thinking more in terms of a combination of hardware (harddisk, processor, ethernet card?) id's and unique files installed on the user's computer, hoping that this is as unique as possible. I have no idea however, how to implement this in AutoIt, if it is at all possible. Is there anyone with ideas? Any help is welcome! Thanks in advance, mr_flet
  17. I have been busy making an installer in AutoIt for a program. It works with GUI, and everything works fine, except the following: When I make an executable file of the installer, and my friend tries to run it, it doesn't show the pictures anymore. I have used absolute paths for the pictures. It seems to me that the pics are not included in the .exe file. Why is that? And how can I work around this? I really need/want the pictures... My second problem is the following: After using the installer, the program -also an executable compiled from an AutoIt script- can be found in the right directory. This program tries to run another program in that same directory. However, when I try to run it, I'm getting an error message saying that a particular function is unknown. This is right, the function is not declared/defined in the program. However, when my friend tries to run it...the program works without spitting out error messages! Do you have any idea how this is possible? Any help is welcome, mr_flet
  18. OK, with pixelchecksum(), I'm drawing the smallest square possible around the rank and the suit of a card. However, sometimes, the checksum is the same for two different cards: card checksum 3d 2130154405 4d 724888128 6d 4281195598 7d 4281195598 9d 102357584 Td 521127524 Jd 1496215483 In the table above, read 3d as: the three of diamonds, etc. Note that the checksums for 6d and 7d are the same. How is this possible, how is the checksum for the square of pixels calculated anyways?
  19. gamepin126: I was afraid that I had to do something like you are suggesting. I hoped that there would be an easier way to do it. OCR souds a little bit complicated for me, as I am an AutoIt noob. Maybe I should look out for a more simple project to begin with, but I'll give OCR a try. There are some interesting posts on this form about OCR. The only fear I have, is that the program becomes too slow. w0uter: I don't like cheating. I'd rather lose than win a game with cheating. Zedna: I don't see what a blackjack game has in common with card recognition in solitaire. I don't want to draw cards myself. How can I use `cards.dll' to recognize cards on my solitaire table?
  20. As my first AutoIt project, I have chosen to build a computer program that solves a game of solitaire for me. I think the Artificial Intelligence won't be that difficult, but I have some problems with recognizing the graphics. (I have no source code yet, tried a few things with pixels, but I deleted them afterwards) How would you approach the problem? How can I recognize the cards on the table? Can it be done with PixelChecksum()? Any ideas are welcome, because I'm stuck at the moment..
×
×
  • Create New...