Jump to content


Photo

RegionWaitChange: wait for region to change or stop changing


  • Please log in to reply
13 replies to this topic

#1 polyethene

polyethene

    Administrator

  • Administrators
  • 5473 posts

Posted 15 August 2007 - 04:56 PM

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

#2 Chris

Chris
  • Administrators
  • 10727 posts

Posted 02 September 2007 - 12:50 AM

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!

#3 Sean

Sean
  • Members
  • 2462 posts

Posted 02 September 2007 - 01:20 AM

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.

#4 polyethene

polyethene

    Administrator

  • Administrators
  • 5473 posts

Posted 02 September 2007 - 11:11 AM

I see why that's necessary, updated. Thanks guys.

#5 David Andersen

David Andersen
  • Members
  • 140 posts

Posted 05 September 2007 - 12:18 PM

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

#6 polyethene

polyethene

    Administrator

  • Administrators
  • 5473 posts

Posted 05 September 2007 - 01:22 PM

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.

#7 David Andersen

David Andersen
  • Members
  • 140 posts

Posted 05 September 2007 - 07:16 PM

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.

#8 polyethene

polyethene

    Administrator

  • Administrators
  • 5473 posts

Posted 05 September 2007 - 11:21 PM

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.

#9 Superfraggle

Superfraggle
  • Members
  • 1019 posts

Posted 06 September 2007 - 01:44 AM

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


#10 lbrtdy

lbrtdy
  • Members
  • 101 posts

Posted 26 May 2009 - 03:27 AM

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!

#11 VxE

VxE
  • Fellows
  • 3511 posts

Posted 26 May 2009 - 04:13 AM

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:

#12 guest3456

guest3456
  • Guests

Posted 27 September 2010 - 01:49 AM

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?

#13 mephamah

mephamah
  • Members
  • 3 posts

Posted 19 May 2011 - 02:40 AM

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?

#14 corona

corona
  • Members
  • 1 posts

Posted 28 June 2012 - 12:50 AM

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