 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
Zener
Joined: 03 Jun 2009 Posts: 15
|
Posted: Thu Jun 04, 2009 10:59 pm Post subject: Detecting no window changes for a period |
|
|
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 |
|
| Back to top |
|
 |
RTFM Guest
|
Posted: Thu Jun 04, 2009 11:09 pm Post subject: |
|
|
| Normaly a previously inactive control will get the focus once the conversion has been finished eg. a Save button --> ControlGetFocus ? |
|
| Back to top |
|
 |
Zener
Joined: 03 Jun 2009 Posts: 15
|
Posted: Fri Jun 05, 2009 1:52 am Post subject: Got Focus |
|
|
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 |
|
| Back to top |
|
 |
Zener
Joined: 03 Jun 2009 Posts: 15
|
Posted: Fri Jun 05, 2009 4:14 am Post subject: Possible Approach - any conmment |
|
|
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 |
|
| Back to top |
|
 |
Zener
Joined: 03 Jun 2009 Posts: 15
|
Posted: Fri Jun 05, 2009 4:24 am Post subject: After loading it got this far |
|
|
| 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 |
|
|
| Back to top |
|
 |
RTFM Guest
|
Posted: Fri Jun 05, 2009 8:40 am Post subject: |
|
|
| Have you checked already what amount of memory the app/process is showing if in idle mode (and to compare against that). |
|
| Back to top |
|
 |
Superfraggle
Joined: 02 Nov 2004 Posts: 1019 Location: London, UK
|
|
| Back to top |
|
 |
Zener
Joined: 03 Jun 2009 Posts: 15
|
Posted: Sat Jun 06, 2009 2:50 am Post subject: Does this help |
|
|
| Certainly does, exactly what I was after- thank you |
|
| Back to top |
|
 |
Zener
Joined: 03 Jun 2009 Posts: 15
|
Posted: Sun Jun 07, 2009 3:57 am Post subject: Error Message |
|
|
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
|
|
| Back to top |
|
 |
Zener
Joined: 03 Jun 2009 Posts: 15
|
Posted: Mon Jun 08, 2009 12:22 am Post subject: Fixed |
|
|
| By moving the function into the main script |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|