AutoHotkey Community

It is currently May 26th, 2012, 5:42 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 10 posts ] 
Author Message
PostPosted: March 13th, 2005, 7:43 am 
Offline

Joined: March 12th, 2005, 7:57 pm
Posts: 15
Code:
;
;MouseLocate by David Bradford
;
;This is an example of how to use this script
;ctrl-alt-l will position my mouse over the submit button on http://www.rottentomatoes.com
;However, to use this, you'll want to scan a control yourself.  Hold down the ctrl key
;and press the left mouse button, then drag the window that appears till it covers the
;control.  Be careful not to highlight or do anything that changes the appearance of the
;control, as the mouse will still do whatever it would normally do on that window.
;
;Go to Notepad and make sure you are using a fixed-width font (as a suggestion, go to
;Format->Font, select Terminal font, Regular style, and the smallest size you can). Then
;paste from the clipboard.
;
;I have switched to all alpha characters as it makes coding easier.
;
;Below, I have put the output after "scanning" the submit button from Rotten Tomatoes.
;Note that the mouse will be put in the center of whatever graphic you use, so narrow it
;down to just the control for best results.
;
;scan_x_start, scan_x_end, scan_y_start, and scan_y_end tell it what rectangle to search
;for the control.
;
;Thanks to Jon for the control selection code
;

^!l::
;Uncomment the next two lines if you want to search the screen instead of the current window
;CoordMode, Pixel, Screen
;CoordMode, Mouse, Screen
scan_x_start=8
scan_x_end  =208
scan_y_start=573
scan_y_end  =707
scan_in_line0 =ttttttcccccccccccccccccccccccccccccccccccccccccccccccccccccccccccntttttt
scan_in_line1 =ttttccctttttttttttttttttttttttttttttttttttttttttttttttttttttttttttnntttt
scan_in_line2 =tttccttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt
scan_in_line3 =ttnctttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttMtt
scan_in_line4 =ttctttttttttnnnnnnntnnntttnnnnnnnnnnntnnnnttttnnntnnnnnnnnnnnttttttttttt
scan_in_line5 =tncttttttttniiiiiiinnictttnicniiiiiiinniiinttniiinnicciiiiiictttttttttMt
scan_in_line6 =tntttttttttnictttnnnnictttnicnictttnicnicicttcicinnictttiittttttttttttMt
scan_in_line7 =tntttttttttniiiiiiinnictttnicniiccciinniccinniccinnictttiittttttttttttMt
scan_in_line8 =tnttttttttttnnnnncicnictttnicnicnnnnicnictiiiitcinnictttiittttttttttttMt
scan_in_line9 =tntttttttttnicnnncicniinnncicniinnnniinictniintcinnictttiittttttttttttMt
scan_in_line10=tttttttttttnciiiiicntniiiiicnniiiiiiinnicttccttcinnictttiitttttttttttMMt
scan_in_line11=tttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttMtt
scan_in_line12=tttMttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttMMtt
scan_in_line13=tttMtttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttMMttt
scan_in_line14=ttttMMtttttttttttttttttttttttttttttttttttttttttttttttttttttttttttMMMtttt
scan_in_line15=ttttttMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMtttttt
WinActivate ahk_id %dmb_lastwin%
Gosub, MouseLocate
return


MouseLocate:
Gosub, ScanScreen
scan_j=0
scan_found=0
scan_last_index=-1
scan_num_searched=0
scan_output=%scan_current_line%
Loop, Parse, scan_output, 0
{
  Transform, scan_cur_line, deref, `%scan_in_line%scan_j%`%
  If (scan_j > 0 and !scan_cur_line)
  {
    scan_found=1
    break
  }
  StringGetPos, scan_index, A_LoopField, %scan_cur_line%
  If(scan_index > -1 and scan_j = 0 or (scan_j > 0 and scan_last_index = scan_index))
  {
    If(scan_j = 0)
    {
      scan_y_adj=%scan_num_searched%
    }
    scan_j++
    scan_last_index=%scan_index%
    StringLen, scan_str_len, scan_cur_line
    if(scan_str_len > scan_max_len)
    {
      scan_max_len=%scan_str_len%
    }
  }
  else
  {
    scan_j=0
  }
  scan_num_searched++
}
if(scan_found)
{
  scan_center_x := scan_max_len / 2
  scan_center_y := scan_j / 2
  Transform, scan_center_x, Round, %scan_center_x%
  Transform, scan_center_y, Round, %scan_center_y%
  scan_center_x := scan_center_x + scan_last_index + scan_x_start
  scan_center_y := scan_center_y + scan_y_start + scan_y_adj
  MouseMove, %scan_center_x%, %scan_center_y%
}
return


~^LButton::
#persistent
CoordMode, Mouse, Screen
CoordMode, Tooltip, Screen
MouseGetPos, scan_x_start, scan_y_start
currentXpos=%scan_x_start%
currentYpos=%scan_y_start%
ToolTip, ., scan_x_start, scan_y_start

WinSet, Transparent, 100, ahk_class tooltips_class32

Loop
{
  MouseGetPos, scan_x, scan_y
  scan_x-=%currentXpos%
  scan_y-=%currentYpos%
  WinMove, ahk_class tooltips_class32, , , , %scan_x%, %scan_y%

  GetKeyState, state, LButton

  if state=u
  {
    tooltip
    break
  }
}

MouseGetPos, scan_x_end, scan_y_end

TrayTip, , Scanning...., , 1

CoordMode, Pixel, Screen
CoordMode, Mouse, Screen
MouseGetPos, scan_x_end, scan_y_end
Gosub, ScanScreen
StringReplace, Clipboard, scan_current_line, 0, `r`n, 1
TrayTip, , Scan complete, , 1
sleep, 1000
TrayTip
return


ScanScreen:
;results returned in %scan_current_line%
scan_current_y=%scan_y_start%
scan_current_x=%scan_x_start%
scan_current_line=
Loop
{
    scan_current_x++
    if scan_current_x > %scan_x_end%
    {
        scan_current_line=%scan_current_line%0
        scan_current_y++
        if scan_current_y > %scan_y_end%
            break
        scan_current_x=%scan_x_start%
        continue
    }
    PixelGetColor, found_color, %scan_current_x%, %scan_current_y%
    StringMid, scan_rgb_r, found_color, 3, 2
    StringMid, scan_rgb_g, found_color, 5, 2
    StringMid, scan_rgb_b, found_color, 7, 2
    scan_rgb_r=0x%scan_rgb_r%
    scan_rgb_g=0x%scan_rgb_g%
    scan_rgb_b=0x%scan_rgb_b%
    scan_rgb_sum:=scan_rgb_r + scan_rgb_g + scan_rgb_b
    if scan_rgb_sum > 0x280
    {
      scan_current_line =%scan_current_line%i
    }
    else if scan_rgb_sum > 0x200
    {
      scan_current_line =%scan_current_line%c
    }
    else if scan_rgb_sum > 0x180
    {
      scan_current_line =%scan_current_line%n
    }
    else if scan_rgb_sum > 0x100
    {
      scan_current_line =%scan_current_line%t
    }
    else if scan_rgb_sum > 0x80
    {
      scan_current_line =%scan_current_line%I
    }
    else
    {
      scan_current_line =%scan_current_line%M
    }
}
return



Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 13th, 2005, 11:58 am 
Offline

Joined: November 8th, 2004, 12:46 am
Posts: 1271
Thats an interesting use for the script, though it will have problems on a system using a different font and color scheme. On the other hand it could produce matches that cannot otherwise be searched for.

_________________
"Anything worth doing is worth doing slowly." - Mae West
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 13th, 2005, 3:09 pm 
Offline

Joined: March 12th, 2005, 7:57 pm
Posts: 15
For some things, yes, but the control in question here is a gif, so that won't apply in this case. For cases such as you are describing, I deal with them like this:

I have the same main .ahk script running on my home and work computers. I check upon loading the script which one I am on (through COMPUTERNAME). Then I take different paths at certain points in the script depending on which machine I am on.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 15th, 2005, 6:44 pm 
This is pretty cool, and I love the original ascii script, but why not just use ImageSearch for this purpose? The nice thing about your method is the "image" is contained right inside the script, but that seems to be the only advantage. Then again I'm a total newbie so maybe I'm missing something subtle?


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: March 15th, 2005, 6:52 pm 
Offline

Joined: March 12th, 2005, 7:57 pm
Posts: 15
One other thing is that my way takes less work (just highlight the image you see on the screen and you've got it). It seemed to me that when I was trying to do the same thing with ImageSearch, I had to do a printscreen, go into paint, isolate the smaller image on the screen, resize the image, etc. However, there is probably a speed disadvantage with my way (haven't really checked).

Also, I had tried ImageSearch a while back and had difficulties making it work. I think I need to give it another shot. I'd like to be able to OCR part of the screen to get the text... that would be really cool.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 16th, 2005, 6:54 am 
Offline

Joined: March 12th, 2005, 7:57 pm
Posts: 15
After getting ImageSearch to work and seeing how fast it is, regarding my code in this post, I just want to say: nevermind! :) I shall use ImageSearch from now on.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 16th, 2005, 2:17 pm 
I just discovered ImageSearch myself and was amazed at the speed. The only thing that bugs me is it doesn't have a WindowName parameter. I'm avoiding this currently by using a Coordmode change, getting the location of the window I want to use, and then sending the search coords relative to that window, but the process would be easier if I could just tell ImageSearch which window to use.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: March 16th, 2005, 2:38 pm 
Offline

Joined: March 2nd, 2004, 3:36 pm
Posts: 10720
This sounds like a good idea: To have ImageSearch and PixelSearch optionally accept a WinTitle/WinText rather than a set of coordinates. The search could then be confined to the boundaries of that window only.

I'll add this to the to-do list. Thanks.


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Amazing Script!
PostPosted: April 20th, 2005, 5:13 am 
Wow you really saved my life with this one

I have been trying now for 3 days to develop my own image search because ImageSearch does not work in 256 color mode.

I'm making a script that takes a random mix of units in StarCraft and sorts them into hot-key groups based on unit type.

I was hoping to be able to use your script to search for a few hundred pixels in an area 200x150 but that takes about 1 second. And I need to do it maybe 12-48 times in a second for 8 different unit icons.

Well it turns out only 10 pixels are needed for 100% accuracy in areas of high contrast so it works very fast.

Please post if you make any improvements to the program :)

thanks

Alex


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: September 16th, 2009, 8:38 am 
Offline

Joined: September 5th, 2009, 3:45 pm
Posts: 10
does the ImageSearch work in games? for example in Warcraft 3? What are the specifications of the image (i know that a bmp should be 24-bit), are there any size restrictions for ImageSearch to work? my can't find any picture.


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 10 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: Alpha Bravo, jrav, Stigg and 12 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group