Ahk图片搜索✚snipaste贴图, 根据贴图位置执行动作

简单说 , 就是用snipaste把图片贴在屏幕上, 然后用ahk搜索该图片的左上角坐标, 搜索到之后, 将坐标分别加上一定数值形成矩形区域, 鼠标中键点击该区域执行设定的动作.

#SingleInstance
CoordMode, Pixel, Screen
~MButton Up::
ImageSearch, xx, yy, 9, 133, 1575, 859, D:\Documents\ahk\imagesearch\豆瓣.png
if ErrorLevel = 1
	MsgBox, ,,未找到图像, 0.5
else
xxx := xx+25
yyy := yy+25
;Sleep, 2000

    CoordMode, Mouse, Screen
    MouseGetPos, x, y
    if (x > xx && x < xxx && y > yy && y < yyy) {
        Run, D:\Documents\ahk\随机豆瓣图书.ahk
		MsgBox,,,随机豆瓣图书, 0.3
        }

return
1 个赞

修改后的版本, 可以搜索多张图片

#SingleInstance
SetTimer, watchPic, 5000
watchPic:
CoordMode, Pixel, Screen

ImageSearch, doubanX, doubanY, 9, 133, 1575, 859, D:\Documents\ahk\imagesearch\豆瓣.png
ImageSearch, searchX, searchY, 9, 133, 1575, 859, D:\Documents\ahk\imagesearch\搜索.png


~LButton Up::
    CoordMode, Mouse, Screen
    MouseGetPos, x, y
    if (x > doubanX && x < doubanX+25 && y > doubanY && y < doubanY+25) {
        Run, D:\Documents\ahk\随机豆瓣图书.ahk
		MsgBox,,,随机豆瓣图书, 0.3
        }
	if (x > searchX && x < searchX+25 && y > searchY && y < searchY+25) {
		MsgBox,,,搜索, 0.5
        }
return

这个干嘛用?

clanahk有一个小的悬浮窗口的功能, 只不过窗口尺寸大了点, 存在感太强了, 这个脚本把贴图和ahk的imagesearch结合, 图片大小能自定义, 相当于是一个悬浮图标, 点击它可以执行自定义的动作比如,打开文件、启动程序、执行快捷键, ahk能做的事就不用多介绍了

所以是个桌面按钮?

楼主之组合技巧思,与 Quicker 悬浮动作功能不谋而合

对的

2024/4/09/01:33
更新了脚本, 取消snipaste贴图 因为snipaste切换贴图组不是很方便 ,改用ahk的gui, 启动时, 显示无边框图片控件, 设有2张图片, 鼠标覆盖图片1(小图)时, 显示图片2(大图) . 并且会搜索大图中的各小图坐标, 根据坐标及其偏移量, 点击时执行相应动作. 相当于是一个
「ahk悬浮图片启动器」


2024/4/09/23:06
配合onenote还挺丝滑


;Menu, Tray, Icon,

CoordMode, Mouse, Screen
SetTimer, Mouse_Move, 100
fixed := 0
doubanX := "", doubanY := ""
searchX := "" searchY := ""
ouluX := "" ouluY := ""
suanshuX := "" suanshuY := ""
runthisX := "" runthisY := ""
varnameX := "" varnameY := ""
ahkhelpX := "" ahkhelpY := ""
spyX := "" spyY := ""
winX := ""
Gui, +OwnDialogs +AlwaysOnTop -Caption
Gui, Margin, 0, 0
Gui, Add, Picture, x0 y0 w25 h25 hwndMyPicture1, D:\图片\PixPin_2024-04-01_20-26-19.png ; 创建第一个图片控件
Gui, Add, Picture, x0 y0 hwndMyPicture2, D:\Documents\ahk\imagesearch\2024-04-08_22-42-23.png ; 创建第二个图片控件
Gui, Show, AutoSize, MyWindow
WinSet, Transparent, 100, MyWindow
OnMessage(0x201, "move_Win")
return

Mouse_Move:
MouseGetPos, x_pos, y_pos
WinGetPos, X, Y, Width, Height, MyWindow
if(X != winX){    ; 检查窗口是否移动了
    winX := X
 goto winmoved  ; 如果窗口x坐标与之前不同, 则跳到winmoved
}
if (x_pos > X && x_pos < X+Width && y_pos > Y && y_pos < Y+Height){

    WinHide, ahk_id %MyPicture1% ; 隐藏第一个图片控件
    WinShow, ahk_id %MyPicture2% ; 显示第二个图片控件
    WinMove, MyWindow,,,,110,120
    WinSet, Transparent, 255, MyWindow

}
else {
    if(fixed = 1){
        return
    }else {
    WinHide, ahk_id %MyPicture2% ; 隐藏第二个图片控件
    WinShow, ahk_id %MyPicture1% ; 显示第一个图片控件
    WinMove, MyWindow,,,,25,25
    WinSet, Transparent, 55, MyWindow
}
}

~MButton Up::    ; 鼠标中键点击,
    WinGetPos, X, Y, Width, Height, MyWindow
    if(width > 50){
	CoordMode, Mouse, Screen
    MouseGetPos, x, y

	if (x > suanshuX && x < suanshuX+34 && y > suanshuY && y < suanshuY+31) {  ; 检查点击位置在小图片坐标区域

		Run, 754计算统计.txt
        }
    }
return
~LButton Up::
    WinGetPos, X, Y, Width, Height, MyWindow
    if(width > 50){
    CoordMode, Mouse, Screen
    MouseGetPos, x, y
    if (x > doubanX && x < doubanX+13 && y > doubanY && y < doubanY+16) {
        Run, 随机豆瓣图书.ahk
		MsgBox,,,随机豆瓣图书, 0.3
        }
	if (x > searchX && x < searchX+22 && y > searchY && y < searchY+20) {
		MsgBox,,,搜索, 0.5
        }
    if (x > ouluX && x < ouluX+12 && y > ouluY && y < ouluY+11) {
		Send, ^{F12}
        }
	if (x > suanshuX && x < suanshuX+34 && y > suanshuY && y < suanshuY+31) {
		Run, 754.ahk
        }



	if (x > runthisX && x < runthisX+105 && y > runthisY && y < runthisY+21) {
		WinActivate, ahk_exe SciTE.exe

		Sleep 500
		WinGetTitle, title, ahk_exe SciTE.exe

		index := InStr(title, "ahk")
		if (index > 0){
			result := SubStr(title, 1, index + 3)

		}
		Run, %result%
        }

	 if (x > varnameX && x < varnameX+77 && y > varnameY && y < varnameY+34 ) {
		Run, varname.ahk
		}
	if (x > ahkhelpX && x < ahkhelpX+77 && y > ahkhelpY && y < ahkhelpY+23 ) {
		Run, AutoHotkey  v2.chm
		}

	if (x > spyX && x < spyX+25 && y > spyY && y < spyY+24) {
		Run, C:\Program Files\AutoHotkey\UX\WindowSpy.ahk
		}
;fixed := 0
}
return

~^LButton up::     ; Ctrl+鼠标左键点击图片右下角10*10像素区域, 固定图片窗口
{
MouseGetPos, x_pos, y_pos
WinGetPos, X, Y, Width, Height, MyWindow
if(x_pos > X+ Width-10 && x_pos < X+ Width && y_pos > Y+ Height-10 && y_pos < Y+Height){
    fixed += 1
    if(fixed = 2){
        fixed :=0
    }
}
}
return


winmoved:    ; 搜索图片, 重新给小图片坐标赋值

CoordMode, pixel, Screen
ImageSearch, doubanX, doubanY, 0, 0, 1599, 899, imagesearch\豆瓣.png
doubanX := doubanX, doubanY := doubanY

ImageSearch, searchX, searchY, 0, 0, 1599, 899, imagesearch\搜索.png
searchX := searchX, searchY := searchY

ImageSearch, ouluX, ouluY, 0, 0, 1599, 899, imagesearch\欧路词典.png
ouluX := ouluX, ouluY := ouluY

ImageSearch, suanshuX, suanshuY, 0, 0, 1599, 899, imagesearch\754.png
suanshuX := suanshuX, suanshuY := suanshuY

ImageSearch, runthisX, runthisY, 0, 0, 1599, 899, imagesearch\运行当前脚本.png
runthisX := runthisX, runthisY := runthisY

ImageSearch, varnameX, varnameY, 0, 0, 1599, 899, imagesearch\varname.png
varnameX := varnameX, varnameY := varnameY

ImageSearch, ahkhelpX, ahkhelpY, 0, 0, 1599, 899, imagesearch\帮助v2.png
ahkhelpX := ahkhelpX, ahkhelpY := ahkhelpY

ImageSearch, spyX, spyY, 0, 0, A_ScreenWidth, A_ScreenHeight, imagesearch\Windowsspy.png
spyX := spyX, spyY := spyY

fixed :=0
return



MyWindowExit:
GuiClose:
ExitApp

move_Win()
{
    PostMessage, 0xA1, 2
}