Plain text
复制到剪贴板
Open code in new window
EnlighterJS 3 Syntax Highlighter
; ScrCmp() :通过比较两个屏幕截图来检测屏幕的变化
; https://www.autohotkey.com/boards/viewtopic.php?f=6&t=82812
; 另一个 PixelChecksum() - 为像素区域生成校验和
; https://www.autohotkey.com/boards/viewtopic.php?f=6&t=4431
#NoEnv
#Warn
#SingleInstance, Force
SetBatchLines, -1
CoordMode, Mouse
;官方例子
;ScrCmp(0, 0, 32, 32)
;MsgBox 检测到屏幕区域变更!
; Win+鼠标左键选取范围
#LButton::
InputRect(vX1, vY1, vX2, vY2)
vW := vX2-vX1, vH := vY2-vY1
if (vInputRectState = -1)
return
Sleep 200
ScrCmp(vX1, vY1, vW, vH)
Tooltip 检测到屏幕区域变更!
;==================================================
;thx jeeswg
;https://www.autohotkey.com/boards/viewtopic.php?t=42810
;based on LetUserSelectRect by Lexikos:
;LetUserSelectRect - select a portion of the screen - Scripts and Functions - AutoHotkey Community
;https://autohotkey.com/board/topic/45921-letuserselectrect-select-a-portion-of-the-screen/
;note: 'CoordMode, Mouse, Screen' must be used in the auto-execute section
;e.g.
;InputRect(vWinX, vWinY, vWinR, vWinB)
;vWinW := vWinR-vWinX, vWinH := vWinB-vWinY
;if (vInputRectState = -1)
; return
InputRect(ByRef vX1, ByRef vY1, ByRef vX2, ByRef vY2)
{
global vInputRectState := 0
DetectHiddenWindows, On
Gui, 1: -Caption +ToolWindow +AlwaysOnTop +hWndhGuiSel
Gui, 1: Color, Red
WinSet, Transparent, 128, % "ahk_id " hGuiSel
Hotkey, *LButton, InputRect_Return, On
Hotkey, *RButton, InputRect_End, On
Hotkey, Esc, InputRect_End, On
KeyWait, LButton, D
MouseGetPos, vX0, vY0
SetTimer, InputRect_Update, 10
KeyWait, LButton
Hotkey, *LButton, Off
Hotkey, Esc, InputRect_End, Off
SetTimer, InputRect_Update, Off
Gui, 1: Destroy
return
InputRect_Update:
if !vInputRectState
{
MouseGetPos, vX, vY
(vX < vX0) ? (vX1 := vX, vX2 := vX0) : (vX1 := vX0, vX2 := vX)
(vY < vY0) ? (vY1 := vY, vY2 := vY0) : (vY1 := vY0, vY2 := vY)
Gui, 1:Show, % "NA x" vX1 " y" vY1 " w" (vX2-vX1) " h" (vY2-vY1)
return
}
vInputRectState := 1
InputRect_End:
if !vInputRectState
vInputRectState := -1
Hotkey, *LButton, Off
Hotkey, *RButton, Off
Hotkey, Esc, Off
SetTimer, InputRect_Update, Off
Gui, 1: Destroy
InputRect_Return:
return
}
;==================================================
ScrCmp( X, Y, W, H, Hwnd:=0x0, Sleep* ) { ; v0.66 By SKAN on D3B3/D3B6 @ tiny.cc/scrcmp
Local
Global A_Args
Sleep[1] := Sleep[1]="" ? 100 : Format("{:d}", Sleep[1])
Sleep[2] := Sleep[2]="" ? 100 : Format("{:d}", Sleep[2])
VarSetCapacity(BITMAPINFO, 40, 0)
NumPut(32, NumPut(1, NumPut(0-H*2, NumPut(W, NumPut(40,BITMAPINFO,"Int"),"Int"),"Int"),"Short"),"Short")
hBM := DllCall("Gdi32.dll\CreateDIBSection", "Ptr",0, "Ptr",&BITMAPINFO, "Int",0, "PtrP",pBits := 0, "Ptr",0, "Int",0, "Ptr")
sDC := DllCall("User32.dll\GetDC", "Ptr",(Hwnd := WinExist("ahk_id" . Hwnd)), "Ptr")
mDC := DllCall("Gdi32.dll\CreateCompatibleDC", "Ptr",sDC, "Ptr")
DllCall("Gdi32.dll\SaveDC", "Ptr",mDC)
DllCall("Gdi32.dll\SelectObject", "Ptr",mDC, "Ptr",hBM)
DllCall("Gdi32.dll\BitBlt", "Ptr",mDC, "Int",0, "Int",H, "Int",W, "Int",H, "Ptr",sDC, "Int",X, "Int",Y, "Int",0x40CC0020)
A_Args.ScrCmp := {"Wait": 1}, Bytes := W*H*4, Count := 0
hMod := DllCall("Kernel32.dll\LoadLibrary", "Str","ntdll.dll", "Ptr")
While ( A_Args.ScrCmp.Wait && (Count<2) )
{
DllCall("Gdi32.dll\BitBlt", "Ptr",mDC, "Int",0, "Int",0, "Int",W, "Int",H, "Ptr",sDC, "Int",X, "Int",Y, "Int",0x40CC0020)
Count := ( (Byte := DllCall("ntdll.dll\RtlCompareMemory", "Ptr",pBits, "Ptr",pBits+Bytes, "Ptr",Bytes) ) != Bytes )
? (Count + 1) : 0
Sleep % (Count ? Sleep[2] : Sleep[1])
} Byte +=1
DllCall("Kernel32.dll\FreeLibrary", "Ptr",hMod)
SX := (CX := Mod((Byte-1)//4, W) + X), SY := (CY := (Byte-1) // (W*4) + Y)
If (Hwnd)
VarsetCapacity(POINT,8,0), NumPut(CX,POINT,"Int"), NumPut(CY,POINT,"Int")
, DllCall("User32.dll\ClientToScreen", "Ptr",Hwnd, "Ptr",&POINT)
, SX := NumGet(POINT,0,"Int"), SY := NumGet(POINT,4,"Int")
If (Wait := A_Args.ScrCmp.Wait)
A_Args.ScrCmp := { "Wait":0, "CX":CX, "CY":CY, "SX":SX, "SY":SY }
DllCall("Gdi32.dll\RestoreDC", "Ptr",mDC, "Int",-1)
DllCall("Gdi32.dll\DeleteDC", "Ptr",mDC)
DllCall("User32.dll\ReleaseDC", "Ptr",Hwnd, "Ptr",sDC)
DllCall("Gdi32.dll\DeleteObject", "Ptr",hBM)
Return ( !!Wait )
}
; ScrCmp() :通过比较两个屏幕截图来检测屏幕的变化 ; https://www.autohotkey.com/boards/viewtopic.php?f=6&t=82812 ; 另一个 PixelChecksum() - 为像素区域生成校验和 ; https://www.autohotkey.com/boards/viewtopic.php?f=6&t=4431 #NoEnv #Warn #SingleInstance, Force SetBatchLines, -1 CoordMode, Mouse ;官方例子 ;ScrCmp(0, 0, 32, 32) ;MsgBox 检测到屏幕区域变更! ; Win+鼠标左键选取范围 #LButton:: InputRect(vX1, vY1, vX2, vY2) vW := vX2-vX1, vH := vY2-vY1 if (vInputRectState = -1) return Sleep 200 ScrCmp(vX1, vY1, vW, vH) Tooltip 检测到屏幕区域变更! ;================================================== ;thx jeeswg ;https://www.autohotkey.com/boards/viewtopic.php?t=42810 ;based on LetUserSelectRect by Lexikos: ;LetUserSelectRect - select a portion of the screen - Scripts and Functions - AutoHotkey Community ;https://autohotkey.com/board/topic/45921-letuserselectrect-select-a-portion-of-the-screen/ ;note: 'CoordMode, Mouse, Screen' must be used in the auto-execute section ;e.g. ;InputRect(vWinX, vWinY, vWinR, vWinB) ;vWinW := vWinR-vWinX, vWinH := vWinB-vWinY ;if (vInputRectState = -1) ; return InputRect(ByRef vX1, ByRef vY1, ByRef vX2, ByRef vY2) { global vInputRectState := 0 DetectHiddenWindows, On Gui, 1: -Caption +ToolWindow +AlwaysOnTop +hWndhGuiSel Gui, 1: Color, Red WinSet, Transparent, 128, % "ahk_id " hGuiSel Hotkey, *LButton, InputRect_Return, On Hotkey, *RButton, InputRect_End, On Hotkey, Esc, InputRect_End, On KeyWait, LButton, D MouseGetPos, vX0, vY0 SetTimer, InputRect_Update, 10 KeyWait, LButton Hotkey, *LButton, Off Hotkey, Esc, InputRect_End, Off SetTimer, InputRect_Update, Off Gui, 1: Destroy return InputRect_Update: if !vInputRectState { MouseGetPos, vX, vY (vX < vX0) ? (vX1 := vX, vX2 := vX0) : (vX1 := vX0, vX2 := vX) (vY < vY0) ? (vY1 := vY, vY2 := vY0) : (vY1 := vY0, vY2 := vY) Gui, 1:Show, % "NA x" vX1 " y" vY1 " w" (vX2-vX1) " h" (vY2-vY1) return } vInputRectState := 1 InputRect_End: if !vInputRectState vInputRectState := -1 Hotkey, *LButton, Off Hotkey, *RButton, Off Hotkey, Esc, Off SetTimer, InputRect_Update, Off Gui, 1: Destroy InputRect_Return: return } ;================================================== ScrCmp( X, Y, W, H, Hwnd:=0x0, Sleep* ) { ; v0.66 By SKAN on D3B3/D3B6 @ tiny.cc/scrcmp Local Global A_Args Sleep[1] := Sleep[1]="" ? 100 : Format("{:d}", Sleep[1]) Sleep[2] := Sleep[2]="" ? 100 : Format("{:d}", Sleep[2]) VarSetCapacity(BITMAPINFO, 40, 0) NumPut(32, NumPut(1, NumPut(0-H*2, NumPut(W, NumPut(40,BITMAPINFO,"Int"),"Int"),"Int"),"Short"),"Short") hBM := DllCall("Gdi32.dll\CreateDIBSection", "Ptr",0, "Ptr",&BITMAPINFO, "Int",0, "PtrP",pBits := 0, "Ptr",0, "Int",0, "Ptr") sDC := DllCall("User32.dll\GetDC", "Ptr",(Hwnd := WinExist("ahk_id" . Hwnd)), "Ptr") mDC := DllCall("Gdi32.dll\CreateCompatibleDC", "Ptr",sDC, "Ptr") DllCall("Gdi32.dll\SaveDC", "Ptr",mDC) DllCall("Gdi32.dll\SelectObject", "Ptr",mDC, "Ptr",hBM) DllCall("Gdi32.dll\BitBlt", "Ptr",mDC, "Int",0, "Int",H, "Int",W, "Int",H, "Ptr",sDC, "Int",X, "Int",Y, "Int",0x40CC0020) A_Args.ScrCmp := {"Wait": 1}, Bytes := W*H*4, Count := 0 hMod := DllCall("Kernel32.dll\LoadLibrary", "Str","ntdll.dll", "Ptr") While ( A_Args.ScrCmp.Wait && (Count<2) ) { DllCall("Gdi32.dll\BitBlt", "Ptr",mDC, "Int",0, "Int",0, "Int",W, "Int",H, "Ptr",sDC, "Int",X, "Int",Y, "Int",0x40CC0020) Count := ( (Byte := DllCall("ntdll.dll\RtlCompareMemory", "Ptr",pBits, "Ptr",pBits+Bytes, "Ptr",Bytes) ) != Bytes ) ? (Count + 1) : 0 Sleep % (Count ? Sleep[2] : Sleep[1]) } Byte +=1 DllCall("Kernel32.dll\FreeLibrary", "Ptr",hMod) SX := (CX := Mod((Byte-1)//4, W) + X), SY := (CY := (Byte-1) // (W*4) + Y) If (Hwnd) VarsetCapacity(POINT,8,0), NumPut(CX,POINT,"Int"), NumPut(CY,POINT,"Int") , DllCall("User32.dll\ClientToScreen", "Ptr",Hwnd, "Ptr",&POINT) , SX := NumGet(POINT,0,"Int"), SY := NumGet(POINT,4,"Int") If (Wait := A_Args.ScrCmp.Wait) A_Args.ScrCmp := { "Wait":0, "CX":CX, "CY":CY, "SX":SX, "SY":SY } DllCall("Gdi32.dll\RestoreDC", "Ptr",mDC, "Int",-1) DllCall("Gdi32.dll\DeleteDC", "Ptr",mDC) DllCall("User32.dll\ReleaseDC", "Ptr",Hwnd, "Ptr",sDC) DllCall("Gdi32.dll\DeleteObject", "Ptr",hBM) Return ( !!Wait ) }
; ScrCmp() :通过比较两个屏幕截图来检测屏幕的变化
; https://www.autohotkey.com/boards/viewtopic.php?f=6&t=82812

; 另一个 PixelChecksum() - 为像素区域生成校验和
; https://www.autohotkey.com/boards/viewtopic.php?f=6&t=4431
#NoEnv
#Warn
#SingleInstance, Force
SetBatchLines, -1
CoordMode, Mouse

;官方例子
;ScrCmp(0, 0, 32, 32)
;MsgBox 检测到屏幕区域变更!

; Win+鼠标左键选取范围
#LButton::

InputRect(vX1, vY1, vX2, vY2)

vW := vX2-vX1, vH := vY2-vY1
if (vInputRectState = -1)
  return
Sleep 200

ScrCmp(vX1, vY1, vW, vH)
Tooltip 检测到屏幕区域变更!

;==================================================
;thx jeeswg
;https://www.autohotkey.com/boards/viewtopic.php?t=42810

;based on LetUserSelectRect by Lexikos:
;LetUserSelectRect - select a portion of the screen - Scripts and Functions - AutoHotkey Community
;https://autohotkey.com/board/topic/45921-letuserselectrect-select-a-portion-of-the-screen/

;note: 'CoordMode, Mouse, Screen' must be used in the auto-execute section

;e.g.
;InputRect(vWinX, vWinY, vWinR, vWinB)
;vWinW := vWinR-vWinX, vWinH := vWinB-vWinY
;if (vInputRectState = -1)
;	return

InputRect(ByRef vX1, ByRef vY1, ByRef vX2, ByRef vY2)
{
  global vInputRectState := 0
  DetectHiddenWindows, On
  Gui, 1: -Caption +ToolWindow +AlwaysOnTop +hWndhGuiSel
  Gui, 1: Color, Red
  WinSet, Transparent, 128, % "ahk_id " hGuiSel
  Hotkey, *LButton, InputRect_Return, On
  Hotkey, *RButton, InputRect_End, On
  Hotkey, Esc, InputRect_End, On
  KeyWait, LButton, D
  MouseGetPos, vX0, vY0
  SetTimer, InputRect_Update, 10
  KeyWait, LButton
  Hotkey, *LButton, Off
  Hotkey, Esc, InputRect_End, Off
  SetTimer, InputRect_Update, Off
  Gui, 1: Destroy
  return

  InputRect_Update:
  if !vInputRectState
  {
    MouseGetPos, vX, vY
    (vX < vX0) ? (vX1 := vX, vX2 := vX0) : (vX1 := vX0, vX2 := vX)
    (vY < vY0) ? (vY1 := vY, vY2 := vY0) : (vY1 := vY0, vY2 := vY)
    Gui, 1:Show, % "NA x" vX1 " y" vY1 " w" (vX2-vX1) " h" (vY2-vY1)
    return
  }
  vInputRectState := 1

  InputRect_End:
  if !vInputRectState
    vInputRectState := -1
  Hotkey, *LButton, Off
  Hotkey, *RButton, Off
  Hotkey, Esc, Off
  SetTimer, InputRect_Update, Off
  Gui, 1: Destroy

  InputRect_Return:
  return
}

;==================================================

ScrCmp( X, Y, W, H, Hwnd:=0x0, Sleep* )  {                                        ; v0.66 By SKAN on D3B3/D3B6 @ tiny.cc/scrcmp
Local
Global A_Args
  Sleep[1] := Sleep[1]="" ? 100 : Format("{:d}", Sleep[1])
  Sleep[2] := Sleep[2]="" ? 100 : Format("{:d}", Sleep[2])

  VarSetCapacity(BITMAPINFO, 40, 0)
  NumPut(32, NumPut(1, NumPut(0-H*2, NumPut(W, NumPut(40,BITMAPINFO,"Int"),"Int"),"Int"),"Short"),"Short")

  hBM := DllCall("Gdi32.dll\CreateDIBSection", "Ptr",0, "Ptr",&BITMAPINFO, "Int",0, "PtrP",pBits := 0, "Ptr",0, "Int",0, "Ptr")
  sDC := DllCall("User32.dll\GetDC", "Ptr",(Hwnd := WinExist("ahk_id" . Hwnd)), "Ptr")
  mDC := DllCall("Gdi32.dll\CreateCompatibleDC", "Ptr",sDC, "Ptr")
  DllCall("Gdi32.dll\SaveDC", "Ptr",mDC)
  DllCall("Gdi32.dll\SelectObject", "Ptr",mDC, "Ptr",hBM)
  DllCall("Gdi32.dll\BitBlt", "Ptr",mDC, "Int",0, "Int",H, "Int",W, "Int",H, "Ptr",sDC, "Int",X, "Int",Y, "Int",0x40CC0020)

  A_Args.ScrCmp := {"Wait": 1},   Bytes := W*H*4,  Count := 0
  hMod := DllCall("Kernel32.dll\LoadLibrary", "Str","ntdll.dll", "Ptr")
  While ( A_Args.ScrCmp.Wait && (Count<2) )
  {
      DllCall("Gdi32.dll\BitBlt", "Ptr",mDC, "Int",0, "Int",0, "Int",W, "Int",H, "Ptr",sDC, "Int",X, "Int",Y, "Int",0x40CC0020)
      Count := ( (Byte := DllCall("ntdll.dll\RtlCompareMemory", "Ptr",pBits, "Ptr",pBits+Bytes, "Ptr",Bytes) ) != Bytes )
               ? (Count + 1) : 0
      Sleep % (Count ? Sleep[2] : Sleep[1])
  }   Byte +=1
  DllCall("Kernel32.dll\FreeLibrary", "Ptr",hMod)

  SX := (CX := Mod((Byte-1)//4, W) + X),    SY := (CY := (Byte-1) // (W*4)   + Y)
  If (Hwnd)
    VarsetCapacity(POINT,8,0), NumPut(CX,POINT,"Int"), NumPut(CY,POINT,"Int")
  , DllCall("User32.dll\ClientToScreen", "Ptr",Hwnd, "Ptr",&POINT)
  , SX := NumGet(POINT,0,"Int"),  SY := NumGet(POINT,4,"Int")

  If (Wait := A_Args.ScrCmp.Wait)
      A_Args.ScrCmp := { "Wait":0, "CX":CX, "CY":CY, "SX":SX, "SY":SY }
  DllCall("Gdi32.dll\RestoreDC", "Ptr",mDC, "Int",-1)
  DllCall("Gdi32.dll\DeleteDC", "Ptr",mDC)
  DllCall("User32.dll\ReleaseDC", "Ptr",Hwnd, "Ptr",sDC)
  DllCall("Gdi32.dll\DeleteObject", "Ptr",hBM)
Return ( !!Wait )
}

 

声明:站内资源为整理优化好的代码上传分享与学习研究,如果是开源代码基本都会标明出处,方便大家扩展学习路径。请不要恶意搬运,破坏站长辛苦整理维护的劳动成果。本站为爱好者分享站点,所有内容不作为商业行为。如若本站上传内容侵犯了原著者的合法权益,请联系我们进行删除下架。