update to AHK v2

This commit is contained in:
2026-06-17 12:09:10 -05:00
parent 9b9405c7d1
commit 9e8ed05b4e
+54 -40
View File
@@ -1,63 +1,77 @@
#SingleInstance, force
CoordMode, Mouse, Screen
#Requires AutoHotkey v2.0 ; v2 only
#SingleInstance force
CoordMode("Mouse", "Screen")
waittime := 120000
waittime := 5000
ogcStop := 13
global nogui := False
Switch A_Args[1]
Switch A_Args
{
Case "on":
Menu, Tray, NoIcon
Goto, Start
Goto(Start)
Case "off":
ExitApp
ExitApp()
default:
for x in A_Args {
MsgBox(x)
}
}
Menu, Tray, Add, Hide GUI, GuiToggle ; Adds a button to toggle the gui
Menu, Tray, Add, Exit, GuiClose ; Exit button
Menu, Tray, NoStandard ; None of the standard tray buttons
Gui, +AlwaysOnTop +ToolWindow
Gui, Add, Button, x3 y3 w55 h20 gStart +Center, Start
Gui, Add, Button, x3 y3 w55 h20 gStop +Center, Stop
Gui, Show, h28 w60, msmv
GuiControl, Hide, Stop ; Since we want the Start button to show first
Return
myGui := Gui()
A_TrayMenu.Delete() ; None of the standard tray buttons
A_TrayMenu.Add("Hide GUI", GuiToggle()) ; Adds a button to toggle the gui
A_TrayMenu.Add("Exit", ExtMen) ; Exit button
myGui.Opt("+AlwaysOnTop +ToolWindow")
ogcButtonStart := myGui.Add("Button", "x3 y3 w55 h20 +Center", "Start")
ogcButtonStart.OnEvent("Click", Start.Bind("Normal"))
ogcButtonStop := myGui.Add("Button", "x3 y3 w55 h20 +Center Hidden", "Stop")
ogcButtonStop.OnEvent("Click", Stop.Bind("Normal"))
myGui.Title := "msmv"
myGui.Show("h28 w60")
Start:
GuiControl, Hide, Start
SetTimer, Msmv, %waittime% ; Checks if the has been input in the last 2 minutes every 30 secs, easier to stop a loop with SetTimer
GuiControl, Show, Stop
Return
Start(A_GuiEvent, GuiCtrlObj, Info, *)
{
ogcButtonStart.Visible := false
SetTimer(Msmv,waittime) ; Checks if the has been input in the last 2 minutes every 30 secs, easier to stop a loop with SetTimer
ogcButtonStop.Visible := true
}
Stop:
GuiControl, Hide, Stop
SetTimer, Msmv, off
GuiControl, Show, Start
Return
Stop(A_GuiEvent, GuiCtrlObj, Info, *)
{
ogcButtonStop.Visible := false
SetTimer(Msmv,0)
ogcButtonStart.Visible := true
}
Msmv:
Msmv()
{
If (A_TimeIdle > waittime) ; https://www.autohotkey.com/docs/Variables.htm#User_Idle_Time
{
Random, x,, %A_ScreenWidth%
Random, y,, %A_ScreenHeight%
MouseMove %x%, %y%
x := Random(, A_ScreenWidth)
y := Random(, A_ScreenHeight)
MouseMove(x, y)
}
}
Return
GuiToggle:
GuiToggle(){
global
If !nogui
{
Gui, Hide
Menu, Tray, Check, Hide GUI
myGui.Hide()
A_TrayMenu.Check("1&")
nogui := True
}
Else
{
Menu, Tray, uncheck, Hide GUI
A_TrayMenu.Uncheck("1&")
nogui := False
Gui, Show
myGui.Show()
}
}
Return
GuiClose:
GuiEscape:
ExitApp ; Closes the app when escape or the exit button is pressed
; exit option from tray menu
ExtMen(A_ThisMenuItem, A_ThisMenuItemPos, MyMenu)
{
ExitApp()
}