AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Imagesearch script

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
Cassax
Guest





PostPosted: Sat Jun 28, 2008 10:51 pm    Post subject: Imagesearch script Reply with quote

Code:
loop, 1
{
ImageSearch, FoundX, FoundY, 0,799, 1279, 0, C:\Users\Jean-Marc Metrailler\Desktop\1.jpg
MouseClick, Left, %FoundX%, %FoundY%
sleep, 10000
}
F4::pause

if ErrorLevel = 2
    MsgBox Could not conduct the search.
else if ErrorLevel = 1
    MsgBox Icon could not be found on the screen.
else
    MsgBox The icon was found at %FoundX%x%FoundY%.


Doesn't seem to work, any suggestions?
Back to top
BoBo²
Guest





PostPosted: Sat Jun 28, 2008 11:28 pm    Post subject: Reply with quote

Code:
ImageSearch, FoundX, FoundY, 0,799, 1279, 0, "C:\Users\Jean-Marc Metrailler\Desktop\1.jpg"
MouseClick, Left, %FoundX%, %FoundY%
Sleep, 1000
If ErrorLevel = 2
    MsgBox Could not conduct the search.
Else if ErrorLevel = 1
    MsgBox Icon could not be found on the screen.
Else
    MsgBox The icon was found at %FoundX%x%FoundY%.

F4::pause
Back to top
scottmattes



Joined: 21 May 2007
Posts: 97
Location: USA

PostPosted: Fri Aug 08, 2008 4:49 pm    Post subject: Reply with quote

I had a thought for making a web app testing script for my work, it seemed so simple.

But, I have not been able to get imagesearch to work yet (after searching I see that I am not the only one to ever have this problem, but so far none of the solutions that I found have worked for me).

I started testing on a web page, but now I am down to testing against my desktop.

- printscreen
- open paint
- paste clipboard
- select just the icon from the top left link on the desktop
- copy it to the clipboard
- file / new
- paste the clipboard
- save as Home_Screen_logo3.jpg, or .png, or .bmp (256 or 24-bit) in the same directory as the .ahk file
- make sure the .ahk is pointing at correct .ext, save, reload
- win-o
- msg that 'Icon could not be found on the screen'

putting quotes, single or dbl, around the filename causes msg 'Could not conduct the search'

autohotkey version 1.0.47.06

Code:

msgbox, win-o to experiment with imagesearch and testing

#o::
  CoordMode Pixel  ; Interprets the coordinates below as relative to the screen rather than the active window.
 
  ;msgbox, searching 0, 0, %A_ScreenWidth%, %A_ScreenHeight%
 
  ImageSearch, OutputVarX, OutputVarY, 0, 0, %A_ScreenWidth%, %A_ScreenHeight%, *250 Home_Screen_logo3.bmp
 
 
  if ErrorLevel = 2
     MsgBox Could not conduct the search.
  else if ErrorLevel = 1
          MsgBox Icon could not be found on the screen.
  else
     MsgBox The icon was found at %FoundX%x%FoundY%.


I do not have NAV running (we use McAfee). I found nothing in McAfee about preventing AutoHotKey.

Does the above steps and code work for you? if not, what did you have to do to make it work?

Thank you for any and all help - have a good weekend gentle beings.
_________________
-------------
Scott Mattes

My small, but growing, collection of scripts.
Back to top
View user's profile Send private message Visit poster's website
engunneer



Joined: 30 Aug 2005
Posts: 6847
Location: Pacific Northwest, US

PostPosted: Fri Aug 08, 2008 6:25 pm    Post subject: Reply with quote

here is the best imagesearch explination I have so far: http://www.autohotkey.com/forum/viewtopic.php?p=110612#110612

I updated the download link today since my other server is gone.
_________________
Unless otherwise noted, all code is untested.
Common Answers: 1.(Loops, Viruses, etc.) 2. Search 3.RTFM
Back to top
View user's profile Send private message Visit poster's website
scottmattes



Joined: 21 May 2007
Posts: 97
Location: USA

PostPosted: Fri Aug 08, 2008 8:35 pm    Post subject: Reply with quote

engunneer,
thank you, that example worked for me.

but, i didn't notice your file link, so i started modifying your example to create the bmp on the fly. i did eventually notice your link and discovered that I had created the 'icon' file incorrectly - fixing that fixed my original code problem.

i am posting my version of your code here as an idea generator for others (idea1=don't code so messy, even if you are frustrated).

thank you all.

Code:

; engunneer
; http://www.autohotkey.com/forum/viewtopic.php?p=110612#110612

; modified by Scott to create the bmp file before the imagesearch

;This script will find the icon for notepad

F11::
  SetTitleMatchMode, 2

  ;start notepad so we have a target to look for
  Run, notepad
  WinWaitActive, Notepad
  sleep, 250

  ; make a bmp file for the test
  clipboard_save=%clipboardall%

  ; i found that sending {alt}{printscreen} didn't work, but ! instead of {alt} does
  Send, !{PRINTSCREEN}
 
  Run mspaint
  WinWait, untitled - Paint,
  IfWinNotActive, untitled - Paint, , WinActivate, untitled - Paint,
  WinWaitActive, untitled - Paint,
 
  ; make intial image size real small so that our paste will expand it to exact size
  send, ^e
  send, 1{tab}1

;  msgbox, take a peek, is the image size really small 1x1
 
 
  send, {enter}
  Send, {SHIFTDOWN}{INS}{SHIFTUP}{ENTER}
  sleep, 250

  ; resize the pasted image so that we have a small target to look for
  send, ^e
  send, 25{tab}25

;  msgbox, take a peek, is the image size small 25x25
 
  send, {enter}
 
  ; save the file
  send, !f
  send, a
  filerecycle, \temp\notepad.bmp
  send, \temp\notepad.bmp
  send, {enter}
  sleep 250
  send, !fx

  clipboard=%clipboard_save%

  ; make sure notepad is visible
  WinWaitActive, Notepad
  sleep 500

  msgbox, search from 0,0 to %A_ScreenWidth%, %A_ScreenHeight%
  sleep 1000
 
  CoordMode Pixel, screen
  ; was 0,0,40,40
  ImageSearch, OutputVarX, OutputVarY, 0, 0, %A_ScreenWidth%, %A_ScreenHeight%, \temp\notepad.bmp
  ;the top left corner of the icon is located at OutputVarX, OutputVarY

if ErrorLevel = 2
    MsgBox Could not conduct the search.
else if ErrorLevel = 1
    MsgBox Icon could not be found on the screen.
else
{
    MsgBox The icon was found at %OutputVarX%x%OutputVarY%.

    coordmode, mouse, screen

    MouseMove, %OutputVarX%, %OutputVarY%, 10
    Sleep, 2000

    ;move away for the next part
    MouseMove, 200, 200, 5, R
    sleep, 2000

    OutputVarX+=5  ;now move 5 pixels in each way
    OutputVarY+=5
    MouseMove, %OutputVarX%, %OutputVarY%, 10
}
msgbox, all done
Return

F12::ExitApp

_________________
-------------
Scott Mattes

My small, but growing, collection of scripts.
Back to top
View user's profile Send private message Visit poster's website
engunneer



Joined: 30 Aug 2005
Posts: 6847
Location: Pacific Northwest, US

PostPosted: Fri Aug 08, 2008 8:56 pm    Post subject: Reply with quote

scottmattes wrote:

Code:

; i found that sending {alt}{printscreen} didn't work, but ! instead of {alt} does
  Send, !{PRINTSCREEN}

The other way is to send {alt down}{printscreen}{alt up}

sending {alt}{printscreen} presses alt, releases alt, presses printscreen, and releases printscreen, which is not what you want.

Also, the screenshot your script is making has the upper left corner of the window too, so if you change your theme or active window color, the bitmap will be invalid. I crop my icon really small (see the one in the other topic) so that it will work on any XP system.

Lastly, there are better ways to take screenshots than !PrintScreen+mspaint inside a script. There are a few scripts that will do it nicely with DLLCall and GDI+ (gdiplus), which doesn't require opening any windows or sending any keys.

Glad the example helped, though.
_________________
Unless otherwise noted, all code is untested.
Common Answers: 1.(Loops, Viruses, etc.) 2. Search 3.RTFM
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group