简易预览取色

CoordMode, Mouse, Screen
CoordMode, Pixel, Screen

SetSystemCursor("IDC_Cross")
Loop
{
	if (GetKeyState("LControl")&&BackgroundColor<>""){
		Clipboard:=Format("0x{:06x}",BackgroundColor)
	}Else if GetKeyState("Esc"){
		RestoreCursors(),ToolTip
		ExitApp
	}
	MouseGetPos xpos, ypos
	PixelGetColor BackgroundColor, xpos, ypos, RGB
	grayLevel:= GetgrayLevel(BackgroundColor)
	TextColor:=grayLevel>192?0x000000:0xffffff

	ToolTip, % "Hex:" BackgroundColor "`n灰度值:" grayLevel "`nLControl:复制至剪切版`nEsc:退出"
	WinGet, hWnd, ID, ahk_class tooltips_class32 
	WinSet, ExStyle, +0x00000020, ahk_id %hWnd%
	ToolTipStyle(hWnd,{Background:BackgroundColor,Text:TextColor})
}

GetgrayLevel(Color){
	Color:=InStr(Color,"#")?SubStr(Format("0x{:06x}",SubStr(Color,2)),3):SubStr(Format("0x{:06x}",Color),3)
	tarr:=[Format("{:d}","0x" SubStr(Color,1,2)),Format("{:d}","0x" SubStr(Color,3,2)),Format("{:d}","0x" SubStr(Color,5,2))]

	Return Floor(tarr[1] * 0.299 + tarr[2] * 0.587 + tarr[3] * 0.114)
}

RestoreCursors()
{
	SPI_SETCURSORS := 0x57
	DllCall( "SystemParametersInfo", UInt,SPI_SETCURSORS, UInt,0, UInt,0, UInt,0 )
}

/*
	Cursor鼠标状态类型:
		IDC_ARROW	常规箭头形
		IDC_IBEAM	"工"字形文本插入
		IDC_WAIT	沙漏形
		IDC_CROSS	十字形精确定位
		IDC_UPARROW	上箭头
		IDC_SIZE	隐藏指针
		IDC_ICON	使用指定光标文件
		IDC_SIZENWSE	左上角右下角大小调整
		IDC_SIZENESW	左下角右上角大小调整
		IDC_SIZEWE	水平调整
		IDC_SIZENS	垂直调整
		IDC_SIZEALL	选中并移动
		IDC_NO		不可用
		IDC_HAND	小手形状
		IDC_APPSTARTING	系统忙
		IDC_HELP	帮助
*/
SetSystemCursor( Cursor = "", cx = 0, cy = 0 )
{
	BlankCursor := 0, SystemCursor := 0, FileCursor := 0 ; init

	SystemCursors = 32512IDC_ARROW,32513IDC_IBEAM,32514IDC_WAIT,32515IDC_CROSS
	,32516IDC_UPARROW,32640IDC_SIZE,32641IDC_ICON,32642IDC_SIZENWSE
	,32643IDC_SIZENESW,32644IDC_SIZEWE,32645IDC_SIZENS,32646IDC_SIZEALL
	,32648IDC_NO,32649IDC_HAND,32650IDC_APPSTARTING,32651IDC_HELP

	If Cursor = ; empty, so create blank cursor 
	{
		VarSetCapacity( AndMask, 32*4, 0xFF ), VarSetCapacity( XorMask, 32*4, 0 )
		BlankCursor = 1 ; flag for later
	}
	Else If SubStr( Cursor,1,4 ) = "IDC_" ; load system cursor
	{
		Loop, Parse, SystemCursors, `,
		{
			CursorName := SubStr( A_Loopfield, 6, 15 ) ; get the cursor name, no trailing space with substr
			CursorID := SubStr( A_Loopfield, 1, 5 ) ; get the cursor id
			SystemCursor = 1
			If ( CursorName = Cursor )
			{
				CursorHandle := DllCall( "LoadCursor", Uint,0, Int,CursorID )
				Break
			}
		}
		If CursorHandle = ; invalid cursor name given
		{
			Msgbox,, SetCursor, Error: Invalid cursor name
			CursorHandle = Error
		}
	}
	Else If FileExist( Cursor )
	{
		SplitPath, Cursor,,, Ext ; auto-detect type
		If Ext = ico 
			uType := 0x1
		Else If Ext in cur,ani
			uType := 0x2
		Else ; invalid file ext
		{
			Msgbox,, SetCursor, Error: Invalid file type
			CursorHandle = Error
		}
		FileCursor = 1
	}
	Else
	{
		Msgbox,, SetCursor, Error: Invalid file path or cursor name
		CursorHandle = Error ; raise for later
	}
	If CursorHandle != Error 
	{
		Loop, Parse, SystemCursors, `,
		{
			If BlankCursor = 1 
			{
				Type = BlankCursor
				%Type%%A_Index% := DllCall( "CreateCursor"
				, Uint,0, Int,0, Int,0, Int,32, Int,32, Uint,&AndMask, Uint,&XorMask )
				CursorHandle := DllCall( "CopyImage", Uint,%Type%%A_Index%, Uint,0x2, Int,0, Int,0, Int,0 )
				DllCall( "SetSystemCursor", Uint,CursorHandle, Int,SubStr( A_Loopfield, 1, 5 ) )
			}
			Else If SystemCursor = 1
			{
				Type = SystemCursor
				CursorHandle := DllCall( "LoadCursor", Uint,0, Int,CursorID )
				%Type%%A_Index% := DllCall( "CopyImage"
				, Uint,CursorHandle, Uint,0x2, Int,cx, Int,cy, Uint,0 )
				CursorHandle := DllCall( "CopyImage", Uint,%Type%%A_Index%, Uint,0x2, Int,0, Int,0, Int,0 )
				DllCall( "SetSystemCursor", Uint,CursorHandle, Int,SubStr( A_Loopfield, 1, 5 ) )
			}
			Else If FileCursor = 1
			{
				Type = FileCursor
				%Type%%A_Index% := DllCall( "LoadImageA"
				, UInt,0, Str,Cursor, UInt,uType, Int,cx, Int,cy, UInt,0x10 ) 
				DllCall( "SetSystemCursor", Uint,%Type%%A_Index%, Int,SubStr( A_Loopfield, 1, 5 ) )
			}			 
		}
	}
}

ToolTipStyle(hwnd:="",Options:=""){
	static bc:="", tc:="", htext:=0, hfont:=0
	If IsObject(Options){
		For key,value In Options
			%key%:=value
		If (Background<>"")
			bc:=((Background&255)<<16)+(((Background>>8)&255)<<8)+(Background>>16)
		If (Text<>"")
			tc:=((Text&255)<<16)+(((Text>>8)&255)<<8)+(Text>>16)
		If (Font||Size){
			If !htext {
				Gui _TTG: Add, Text, +hwndhtext
				Gui _TTG: +hwndhgui +0x40000000
			}
			Gui _TTG: Font, %Size%, %Font%
			GuiControl _TTG: Font, %htext%
			hfont:=DllCall("SendMessage", "Ptr", htext, "Uint", 0x31, "Ptr", 0, "Ptr", 0)
		}
	}
	If (hwnd&&(bc||tc||hfont)){
		DllCall("UxTheme.dll\SetWindowTheme", "ptr", hwnd, "Ptr", 0, "UintP", 0)
		If (bc)
			DllCall("SendMessage", "Ptr", hwnd, "Uint", 1043, "Ptr", bc, "Ptr", 0)
		If (tc)
			DllCall("SendMessage", "Ptr", hwnd, "Uint", 1044, "Ptr", tc, "Ptr", 0)
		If (hfont)
			DllCall("SendMessage", "Ptr", hwnd, "Uint", 0x30, "Ptr", hfont, "Ptr", 0)
	}
}
AHKV1其他

ahk使用正则,在去除杂乱空格,然后字符之间加空格

2021-12-15 17:14:13

AHKV1

v1中文字符串过滤

2021-12-20 16:34:58

3 条回复 A文章作者 M管理员
  1. mp911

    谢谢大佬分享

  2. 1河许人

    有参考价值,我最近也在搞这一块

    • 蜜獾哥

      显示用btt ,btt可以背景色与字体色反色显示有个灰度计算公式 hex转rgb后
      Graylevel=0.299*R+0.587*G+0.144*B Graylevel值以192为分界 判断深浅色后可以在btt背景为取色值后 字体色根据Graylevel值决定是显示深黑还是深白

个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索