Code: Select all
#include Gdip_All.ahk
global switch := false
F1::
switch := !switch
if (switch) {
SetTimer, watcher, 500
} else {
SetTimer, watcher, off
}
return
watcher()
{
if (switch) {
WinGetPos, X, Y, W, H, A
promise := new Snap(0, 0, W, H)
if (promise.HasChanged) {
Send {PrintScreen}
}
tooltip_fn((promise.HasChanged ? "Something" : "Nothing") " has changed.")
}
}
class Snap
{
static pToken := Gdip_Startup()
static hModule := DllCall("LoadLibrary", "Str", "ucrtbase.dll", "Ptr")
__New(x1, y1, x2, y2)
{
this.x := x1
this.y := y1
this.w := x2 - x1
this.h := y2 - y1
this.Original := Bitmap.CreateLocked(this.x, this.y, this.w, this.h)
}
HasChanged[] {
get {
Current := Bitmap.CreateLocked(this.x, this.y, this.w, this.h)
return DllCall("ucrtbase\memcmp"
, "Ptr", this.Original.scan0
, "Ptr", Current.scan0
, "Ptr", Current.countBytes)
}
}
}
class Bitmap
{
__New(x, y, w, h)
{
this.ptr := Gdip_BitmapFromScreen(x "|" y "|" w "|" h)
this.w := w
this.h := h
}
__Delete()
{
this.UnlockBits()
Gdip_DisposeImage(this.ptr)
}
CreateLocked(x, y, w, h)
{
Bmp := new Bitmap(x, y, w, h)
Bmp.LockBits()
return Bmp
}
LockBits()
{
if this.bmData
throw Exception("Already locked.", -1)
Gdip_LockBits(this.ptr, 0, 0, this.w, this.h, stride, scan0, bmData)
this.scan0 := scan0
this.bmData := bmData
this.countBytes := this.w * stride
}
UnlockBits()
{
if !this.bmData
throw Exception("Wasn't locked beforehand.", -1)
Gdip_UnlockBits(this.ptr, this.bmData)
this.bmData := ""
}
}
tooltip_fn(input)
{
ToolTip % input
SetTimer, rm_tooltip, -1000
}
rm_tooltip()
{
ToolTip
return
}