一个简单的悬浮俯卧撑记录器 鼠标悬浮到窗口显示输入框, 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