AutoHotkey Community

It is currently May 26th, 2012, 7:23 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 10 posts ] 
Author Message
PostPosted: June 4th, 2009, 11:59 pm 
Offline

Joined: June 3rd, 2009, 4:36 am
Posts: 15
This automating an OCR application is driving me nuts.
Main issue is that some conversions take seconds, other minutes depending upon the complexity. And this all happens in the same window (although the window title changes this does not reflect the activity) so I can not trigger off window changes.

So the question - is there a way to detect activity (or rather lack of it) within a window and trigger an action if nothing changes over a certain period. I tried catching the mouse cursor type but the application when working uses a "Unknown" cursor (a custom crosshatch) as when the application is finished processing and idle.

Any suggesttions would be most welcome


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 5th, 2009, 12:09 am 
Normaly a previously inactive control will get the focus once the conversion has been finished eg. a Save button --> ControlGetFocus ?


Report this post
Top
  
Reply with quote  
 Post subject: Got Focus
PostPosted: June 5th, 2009, 2:52 am 
Offline

Joined: June 3rd, 2009, 4:36 am
Posts: 15
No control seems to get focus when process complete, but I do notice that the top window focus comes and goes during processing (Dark blue becomes shaded while the application is busy and focus is lost).

So to know when I can safely close I probably need to check it the main window has the focus uninterupted for 30 seconds - then can assume "all done'

Is this possible or feasible

Thanks for your advice


Report this post
Top
 Profile  
Reply with quote  
PostPosted: June 5th, 2009, 5:14 am 
Offline

Joined: June 3rd, 2009, 4:36 am
Posts: 15
If the top window is tiltled "OCR- Page 1 0f 5" then I am guessing the following code may work to detect if the application is idle

Code:
SetTitleMatchMode, 2  ; Work on abreviated title

IfWinActive, OCR
{
   Sleep,1000  ;sleep 1 second
   IfWinInactive, OCR  ; if the top window becomes inactive
       {
        A_Index :=0  ; reset the loop counter - can you do this ?
       }
    If  A_Index=10 return  ;if 10 secs have passed without the window   altering then exit the loop
} ;end of loop[\code]

Any thoughts from the experts ? Much appreciated


Report this post
Top
 Profile  
Reply with quote  
PostPosted: June 5th, 2009, 5:24 am 
Offline

Joined: June 3rd, 2009, 4:36 am
Posts: 15
Code:
SetTitleMatchMode, 2  ; Work on abreviated title
Loopcount:=0
IfWinActive, OCR
{
   Sleep,1000  ;sleep 1 second
  Loopcount=Loopcout+1
   IfWinNotActive, OCR  ; if the top window becomes inactive
       {
        Loopcount :=0  ; reset the loop counter - can you do this ?
       }
    If  %Loopcount%=10
{
return
}  ;if 10 secs have passed without the window   altering then exit the loop
} ;end of loop


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 5th, 2009, 9:40 am 
Have you checked already what amount of memory the app/process is showing if in idle mode (and to compare against that).


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: June 5th, 2009, 2:02 pm 
Offline

Joined: November 2nd, 2004, 2:43 pm
Posts: 1019
Location: London, UK
does this help??

http://www.autohotkey.com/forum/viewtop ... waitchange

_________________
Steve F AKA Superfraggle

http://r.yuwie.com/superfraggle


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Does this help
PostPosted: June 6th, 2009, 3:50 am 
Offline

Joined: June 3rd, 2009, 4:36 am
Posts: 15
Certainly does, exactly what I was after- thank you


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Error Message
PostPosted: June 7th, 2009, 4:57 am 
Offline

Joined: June 3rd, 2009, 4:36 am
Posts: 15
Just trying to use the code in the example

Code:
#z::
#Include RegionWaitChange.ahk

Run, notepad ; open notepad
WinWait, Untitled - Notepad ; wait for window to exist

ControlSetText, Edit1 ; delete any current text
MsgBox, Notepad is empty`, press F12 to fill it with random text.

; monitor the region of 100px width and height from coordinate (10, 10):
RegionWaitChange(10, 10, 100, 100, "Untitled - Notepad")
; once the region changed the script will continue here:
MsgBox, Notepad has changed! (RegionWaitChange completed)

WinClose
ExitApp

F12::
VarSetCapacity(dots, 5000, Asc(".")) ; fill a variable with something
ControlSetText, Edit1, %dots%, Untitled - Notepad ; change the text on notepad artificially
dots = ; free variable
Return



When I try to run the example above I get an error message "In RegionWaitChange.AKH : A label must not point to a function

016 : Return
--> 034: {

but the values returned in error message do not seem to relate to the file at all
Code:

/*
   Function: RegionWaitChange
   
   Waits for a region of a window to change.
   
   Parameters:
      x, y - coordinates relative to window
      w, h - size of the region to monitor (default: 1 and 1 respectively)
      t - window title (default: Last Found Window <http://www.autohotkey.com/docs/LastFoundWindow.htm>)
      f - check frequency in milliseconds (default: 500)
      s - maximum image buffer size (default: 64 MiB)
      inv - *reserved*
   
   Function: RegionWaitStatic
   
   Identical to the previous function except waits until the specified region stops changing.
   
   Function: DCCBitmapHash
   
   Returns an MD5 hash of a window region.
   
   Parameters:
      hwnd - window handle
      x, y - coordinates relative to window
      w, h - size of region
      s - maximum image buffer size (default: 64 MiB)
   
   About: License
      - Version 1.01 by Titan <http://www.autohotkey.net/~Titan/#regionwaitchange>
      - GNU General Public License 3.0 or higher <http://www.gnu.org/licenses/gpl-3.0.txt>
*/


RegionWaitChange(x, y, w = 1, h = 1, t = "", f = 500, s = 67108864, inv = false) {
   hwnd := WinExist(t)
   Loop {
      hc := DCCBitmapHash(hwnd, x, y, w, h, s)
      If ((inv ? hc = lhc : hc != lhc) and lhc != "")
         Return, true
      lhc := hc
      Sleep, f
   }
}

RegionWaitStatic(x, y, w = 1, h = 1, t = "", f = 1000, s = 67108864) {
   RegionWaitChange(x, y, w, h, t, f, s, true)
}

DCCBitmapHash(hwnd, x, y, w = 1, h = 1, s = 67108864) {
   hdc := DllCall("GetDC", "UInt", hwnd)
   hcdc := DllCall("CreateCompatibleDC", "UInt", hdc)
      
   hbmp := DllCall("CreateCompatibleBitmap", "UInt", hdc, "UInt", w, "UInt", h)
   DllCall("SelectObject", "UInt", hcdc, "UInt", hbmp)
   
   DllCall("BitBlt", "UInt", hcdc, "Int", 0, "Int", 0, "Int", w, "Int", h
      , "UInt", hdc, "Int", x, "Int", y, "UInt", 0x00CC0020) ; SRCCOPY
   
   sz := VarSetCapacity(bits, s, 0)
   sz := DllCall("GetBitmapBits", "UInt", hbmp, "UInt", sz, "UInt", &bits)
   
   DllCall("DeleteObject", "UInt", hbmp)
   DllCall("DeleteDC", "UInt", hcdc)
   DllCall("ReleaseDC", "UInt", hwnd, "UInt", hdc)
   
   Return, GetHashCode(bits, sz)
}

#Include Hash.ahk



Has anyone any thoughts - sorry to be a newbie pest





Code:


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Fixed
PostPosted: June 8th, 2009, 1:22 am 
Offline

Joined: June 3rd, 2009, 4:36 am
Posts: 15
By moving the function into the main script


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, bobbysoon, BrandonHotkey, Google Feedfetcher, joetazz, krajan, over21, RaptorX, rbrtryn, SKAN and 75 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