Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

RegionWaitChange: wait for region to change or stop changing


  • Please log in to reply
13 replies to this topic
polyethene
  • Administrators
  • 5517 posts
  • Last active: Oct 19 2014 02:44 PM
  • Joined: 26 Oct 2012
Waits for a region of a window to change or stop changing by using GDI bitmap functions and MD5 hashes. Requires Windows Vista or Windows XP. Earlier versions of Windows can be supported by using PhiLho and Laszlo's binary encoding libraries, although they're much slower. Details included in the scripts.

Download

Chris
  • Administrators
  • 10727 posts
  • Last active:
  • Joined: 02 Mar 2004
Really nice function. Amazingly compact.

Since I know some people have asked for this, I'm surprised no one replied. I suspect it's definitely getting used though!

Sean
  • Members
  • 2462 posts
  • Last active: Feb 07 2012 04:00 AM
  • Joined: 12 Feb 2007
I was already aware of this script, but now I actually read it. Excellent stuffs!
I have a suggestion. Use DeleteDC, not ReleaseDC, for hcdc.

polyethene
  • Administrators
  • 5517 posts
  • Last active: Oct 19 2014 02:44 PM
  • Joined: 26 Oct 2012
I see why that's necessary, updated. Thanks guys.

David Andersen
  • Members
  • 140 posts
  • Last active: Jun 28 2011 04:54 PM
  • Joined: 15 Jul 2005
Thanks Titan.

The script certainly look interesting, but I cannot get it to work. I am sure it is just my incompetence. Specifically, I cannot see what the following line does
hwnd := WinExist(t)
WinExist does not seem to be a function in the documentation, and hwnd is always 0x0.

An example script just measuring change in the active windows would be very good.

Regards,

David

polyethene
  • Administrators
  • 5517 posts
  • Last active: Oct 19 2014 02:44 PM
  • Joined: 26 Oct 2012
WinExist() is a built-in function, maybe you need to update your version of AutoHotkey. Here is a working example:

#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
If you still can't get your script to work please post it.

David Andersen
  • Members
  • 140 posts
  • Last active: Jun 28 2011 04:54 PM
  • Joined: 15 Jul 2005
Thanks a lot Titan! It works like a charm! One use of this script would be when you start an operation that takes several minutes to finish. It would then be good to be able to push a single hotkey which would monitor the entire screen (maybe even double screens :)) and make a sound when the screen changes.

polyethene
  • Administrators
  • 5517 posts
  • Last active: Oct 19 2014 02:44 PM
  • Joined: 26 Oct 2012
Thanks, I appreciate that. I originally wrote this for my game macros but then realized it could be used for other purposes such as event handling in the cases you mentioned. I believe it was a long requested feature as well.

Superfraggle
  • Members
  • 1019 posts
  • Last active: Sep 25 2011 01:06 AM
  • Joined: 02 Nov 2004
Ive just combined this with Rolands Gui from his wincut script to make it even easier for newcomers.

#Include RegionWaitChange.ahk

+#LButton:: 
CoordMode, Mouse
MouseGetPos, sx, sy, win 
WinGettitle,title, ahk_id%win% 
Gui, +lastfound +alwaysOnTop +toolwindow -caption 
Gui, Color, 00FFFF 
WinSet, Transparent, 50 
Gui, Show, noActivate 
Loop { 
    if !getKeyState("LButton", "p") 
      break 
    MouseGetPos, x, y 
    Gui, Show, % "x" sx "y" sy "w" x-sx "h" y-sy 
  } WinGetPos, gx, gy, w, h 
Gui, destroy
msgbox %title%
RegionWaitstatic(gx, gy, w, h, title)
msgbox
exitapp
return


lbrtdy
  • Members
  • 101 posts
  • Last active: Jan 22 2010 12:24 AM
  • Joined: 13 Apr 2009
I'm if correct that script waits until a region has changed or stops changing, meaning it pauses the script? How do I make it so that the script continues until the region changes? Thanks!

VxE
  • Moderators
  • 3622 posts
  • Last active: Oct 24 2013 04:25 AM
  • Joined: 07 Oct 2006

I'm if correct that script waits until a region has changed or stops changing, meaning it pauses the script? How do I make it so that the script continues until the region changes? Thanks!

SetTimer, SomethingToDo, 5000

RegionWaitWhatever(arg, arrg, arrrg)

SetTimer, SomethingToDo, off

return

SomethingToDo:

msgbox, 0, Working...,...yeah, right., 3

return
:lol:

guest3456
  • Guests
  • Last active:
  • Joined: --
in the zip, the files have GPL licenses, but on your scripts webpage, it says BSD license

which is the correct license for this function?

mephamah
  • Members
  • 3 posts
  • Last active: May 27 2011 09:39 PM
  • Joined: 12 Apr 2011
Ive been playing with the WaitRegionStatic function because I'd like to write a hotkey which navigates a series of pages on a website and is not dependent on predetermined sleep delays (due to the variability of internet speed this is not feasible). However, I have found that the script always seems to continue before the region actually stops changing. For example, to test this function, I was watching a youtube video of a strobe light and designated a certain pixel to be monitored. Although the entire region was changing colour quite rapidly, the script continued after a few seconds, indicating that the region was static when in fact it was not. I am using windows vista as is required by this function. Any suggestions?

corona
  • Members
  • 1 posts
  • Last active: Jun 27 2012 11:39 PM
  • Joined: 27 Jun 2012
Thanks for this script, it's been very useful to me for scripting some automated test suites for development.

It actually hasn't worked for me on some computers however, I chased it down to GetHashCode() always returning null.
Turns out DllCall("advapi32\CryptAcquireContext doesn't always work immediately, I was getting NTE_BAD_KEYSET error. I used
<!-- m -->http://msdn.microsof...ry ... 85).aspx<!-- m -->
as a guide to fix it:
GetHashCode(ByRef data, len = -1, alg_id = 0x8003) {
	err := DllCall("advapi32\CryptAcquireContext", "UIntP", hProv, "UInt", 0, "UInt", 0, "UInt", 1, "UInt", 0) ; PROV_RSA_FULL = 1
	if err = 0
	{
		err := DllCall("GetLastError")
		if (err & 0xFFFFFFFF) = 0x80090016 ;NTE_BAD_KEYSET
		{
			;No default container was found. Attempt to create it.
			err := DllCall("advapi32\CryptAcquireContext", "UIntP", hProv, "UInt", 0, "UInt", 0, "UInt", 1, "UInt", 8) ; PROV_RSA_FULL = 1, CRYPT_NEWKEYSET = 0x00000008
			if err = 0
			{
				msgbox, Problem with the WinCypt subsystem
				exit
			}
		}
	}
	DllCall("advapi32\CryptCreateHash", "UInt", hProv, "UInt", alg_id, "UInt", 0, "UInt", 0, "UIntP", hHash)
	DllCall("advapi32\CryptHashData", "UInt", hHash, "UInt", &data, "UInt", len < 0 ? VarSetCapacity(data) : len, "UInt", 0)

	ssz := VarSetCapacity(sz, 4, 0)
	DllCall("advapi32\CryptGetHashParam", "UInt", hHash, "UInt", 4, "UIntP", sz, "UIntP", ssz, "UInt", 0)
	VarSetCapacity(HashVal, sz, 0)
	DllCall("advapi32\CryptGetHashParam", "UInt", hHash, "UInt", 2, "UInt", &HashVal, "UIntP", sz, "UInt", 0)
	BinaryToString(str, HashVal, false, sz)
  
	DllCall("advapi32\CryptDestroyHash", "UInt", hHash)
	DllCall("advapi32\CryptReleaseContext", "UInt", hProv, "UInt", 0)
	Return, str
}

Cheers,
Andrew