俯卧撑悬浮记录器GIF

一个简单的悬浮俯卧撑记录器 鼠标悬浮到窗口显示输入框, enter键写入文本, 双击显示记录的文本

SetTitleMatchMode 2
SetTimer,mousepos, 200
FileRead, fileContent, 俯卧撑计数坐标.txt
coord := StrSplit(fileContent, " ")
wincoordX := coord[1]
wincoordY := coord[2]

Gui, +OwnDialogs +AlwaysOnTop -Caption +ToolWindow
Gui, Margin, 0, 0
Gui, Add, Picture, x0 y0 w25 h25 hwndMyPicture1 gPictureDoubleClick, D:\Documents\ahk\imagesearch\2024-04-11_19-07-35.png
Gui, Add, Edit, Number h25 vNumCount
Gui, Add, Button, Default, OK
Gui, Show, , pushups
;WinSet, Transparent, 255, pushups
WinMove, pushups,,%wincoordX%, %wincoordY%, 25, 25

OnMessage(0x201, "move_Win")
return
move_Win()
{
    PostMessage, 0xA1, 2
}



ButtonOK:                                                                              ; 将edit数字写入文本
	Gui, Submit, NoHide
	FormatTime, CurrentDateTime,, yyyy/MM/dd HH:mm:ss
	FileAppend, %CurrentDateTime% %NumCount%`n, 俯卧撑计数.txt
	GuiControl,, NumCount
	MsgBox,,,%NumCount% , 0.6
return




mousepos:
CoordMode, Mouse, screen
MouseGetPos, x, y
WinGetPos, Xpushup_win, Ypushup_win, Widthpushup_win, Heightpushup_win, pushups
if (x>(Xpushup_win)&& x<(Xpushup_win +25) && y>(Ypushup_win) && y<(Ypushup_win+25)) {   ; 如果鼠标悬浮在小窗口则显示输入框
	WinMove, pushups,,,, 25, 50
	SetTimer, inputnum, 100
}
	return




inputnum:                                                                                 ; 激活输入框并检查鼠标是否离开
	WinActivate, pushups
	;ControlFocus, Edit1
	CoordMode, Mouse, Screen
    MouseGetPos, xbox, ybox
    WinGetPos, winboxX, winboxY, Wwinbox, Hwinbox, pushups
	if(xbox < winboxX or (xbox > (winboxX+Wwinbox+50)) or ybox < (winboxY-50) or ybox > (winboxY+Hwinbox+50)){  ; 鼠标离开则折叠输入框
		WinMove, pushups,,,, , 25
		SetTimer, inputnum, off
	}
return


PictureDoubleClick:                                                                            ; 双击小窗口打开记录
    if (A_GuiEvent = "DoubleClick") {
	Run, 俯卧撑计数.txt
	SetTimer, watchnotpad, 100
    }
return



watchnotpad:                                                                                 ; 如果鼠标坐标< 记事本x坐标则关闭记事本
	CoordMode, Mouse, Screen
    MouseGetPos, xbox, ybox
    WinGetPos, notepadX, notepadY, Wnotepad, Hnotepad, Notepad
	if(xbox <notepadX ){  ;;or xbox > notepadX+Wnotepad or ybox<notepadY or ybox>notepadY+Hnotepad
	WinClose, Notepad5
	SetTimer, watchnotpad, off
}

return

~LButton Up::                                                                           ; 保存窗口坐标
	Sleep 200
	CoordMode, Mouse, Screen
    MouseGetPos, xpushups, ypushups
    WinGetPos, winXpushups, winYpushups, Widthpushups, Heightpushups, pushups
	if(winXpushups != wincoordX) {
		wincoordX := winXpushups
		wincoordY := winYpushups
	}
return


图标改用动图, 不得已语法也换成了v2版 动图在这里:

;https://www.autohotkey.com/boards/viewtopic.php?f=96&t=125741&p=558177&hilit=gui+gif#p558177

#Requires AutoHotkey v2.0
#include ImagePut.ahk   ;https://github.com/iseahound/ImagePut/blob/master/ImagePut.ahk
;https://github.com/iseahound/ImagePut/wiki/Add-Image-to-AutoHotkey-GUI
SetTimer mousepos, 200
	wincoordX := A_ScreenWidth/2
	wincoordY := A_ScreenHeight/2
	if FileExist("俯卧撑计数坐标.txt")
{
fileContent := FileRead( "俯卧撑计数坐标.txt")
coord := StrSplit(fileContent, " ")
wincoordX := coord[1]
wincoordY := coord[2]
}







app := Gui("-Border")
app := Gui("-Caption +AlwaysOnTop +ToolWindow")
app.MarginX := "0"
app.MarginY := "0"
image := "D:\Documents\ahk\imagesearch\PixPin_2024-04-13_03-23-55.gif"
app.Title := "pushups"
display := app.Add("Picture", , "D:\Documents\ahk\imagesearch\2024-04-11_19-07-35.png")
width := ImageWidth(image)
height := ImageHeight(image)
display.move(,, 1*width, 1*height)
image_hwnd1 := ImageShow(image,, [0, 0, , ], 0x40000000 | 0x10000000 | 0x8000000,, display.hwnd, False)
app.AddEdit("vNum")
MyBtn := app.Add("Button", "Default w10", "OK").OnEvent("Click", MyBtn_Click)
display.OnEvent("DoubleClick", Call_back )
app.Show("xCenter y0 AutoSize")
WinMove wincoordX,wincoordY,30,20, "pushups"

;Some useful functions.
Play(hwnd) => PostMessage(0x8001,,,, hwnd)
Pause(hwnd) => PostMessage(0x8002,,,, hwnd)
Stop(hwnd) => PostMessage(0x8002, 1,,, hwnd)

;Use PostMessage to asynchronously start playback!
Play("ahk_id" image_hwnd1)


OnMessage(0x201, move_win) ; 0x201 是 WM_MOUSEMOVE 消息的ID
return
move_win(*)
{
    PostMessage 0xA1, 2,,, "pushups"
    return
}



MyBtn_Click(*)  ; 将edit数字写入文本
{
	Saved  := app.Submit(0)
	CurrentDateTime := FormatTime("R")

	FileAppend CurrentDateTime " " Saved.Num "`n", "俯卧撑计数.txt"
	ControlSetText("", "Edit1", "pushups")
	MsgBox Saved.Num , ,"T0.5"
return
}


mousepos()
{

CoordMode "Mouse", "screen"
MouseGetPos &xpos, &ypos
WinGetPos &Xpushup_win, &Ypushup_win, &Widthpushup_win, &Heightpushup_win, "pushups"
if (xpos>(Xpushup_win)&& xpos<(Xpushup_win +30) && ypos>(Ypushup_win) && ypos<(Ypushup_win+50)) {   ; 如果鼠标悬浮在小窗口则显示输入框
	WinMove ,,30, 37, "pushups"  ;"pushups"
	;SetTimer inputnum, 100
}else
{
	WinMove ,,30, 20, "pushups"

}
	return
}

~LButton Up::                                                                           ; 保存窗口坐标
{
	global wincoordX
	global wincoordY
	Sleep 200
	CoordMode "Mouse", "Screen"
    MouseGetPos &xpushups, &ypushups
    WinGetPos &winXpushups, &winYpushups, &Widthpushups, &Heightpushups, "pushups"
	if(winXpushups != wincoordX) {
		wincoordX := winXpushups
		wincoordY := winYpushups
		if FileExist("俯卧撑计数坐标.txt")
		{
		FileDelete "俯卧撑计数坐标.txt"
		}
		FileAppend wincoordX " " wincoordY , "俯卧撑计数坐标.txt"
		;FileAppend CurrentDateTime . Saved.Num "`n", "俯卧撑计数.txt"
	}
return
}



call_back(*)
{
Run "俯卧撑计数.txt"
}