这段代码通过创建了一个 实时拾取屏幕颜色的工具。当鼠标移动时,它会动态显示鼠标当前位置的颜色,并更新窗口背景颜色和 RGB 值。

取色框一直都保持在屏幕显示之内,方便用户查看。

 

; https://www.autohotkey.com/boards/viewtopic.php?f=6&t=76745

#NoEnv
#SingleInstance, Force
CoordMode, Mouse, Screen
CoordMode, Pixel, Screen

Gui New, -Caption +Border +hWndhWnd +Disabled +AlwaysOnTop
Gui, Margin, 15, 30
Gui, Add, Edit, w60 Center, FFFFFF
Gui, Show

WinGetPos, X, Y, W, H, ahk_id %hWnd%
PX:=X, PY:=Y
Loop
{
  MouseGetPos, X, Y
  If ! (X=PX and Y=PY)                          
    { 
      WinMoveZ(hWnd, 16, X, Y, W, H), PX:=X, PY:=Y
      PixelGetColor, C, %X%, %Y%, RGB
      Gui, Color, % PC:=C
      GuiControl,,Edit1, % Format("{:06X}",C)
    }       
  Sleep 50  
}


F2::Gui +AlwaysOnTop
Esc:: ExitApp


WinMoveZ(hWnd, C, X, Y, W, H, Redraw:=0) { ;  WinMoveZ v0.5 by SKAN on D35V/D361 @ tiny.cc/winmovez 
Local V:=VarSetCapacity(R,48,0), A:=&R+16, S:=&R+24, E:=&R, NR:=&R+32, TPM_WORKAREA:=0x10000
  C:=( C:=Abs(C) ) ? DllCall("SetRect", "Ptr",&R, "Int",X-C, "Int",Y-C, "Int",X+C, "Int",Y+C) : 0
  DllCall("SetRect", "Ptr",&R+16, "Int",X, "Int",Y, "Int",W, "Int",H)
  DllCall("CalculatePopupWindowPosition", "Ptr",A, "Ptr",S, "UInt",TPM_WORKAREA, "Ptr",E, "Ptr",NR)
  X:=NumGet(NR+0,"Int"),  Y:=NumGet(NR+4,"Int")
Return DllCall("MoveWindow", "Ptr",hWnd, "Int",X, "Int",Y, "Int",W, "Int",H, "Int",Redraw)
}

 

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