Skip to content

Instantly share code, notes, and snippets.

@phense
Last active February 12, 2022 14:57
Show Gist options
  • Save phense/00e53ab912d504205a9454aca8766a2f to your computer and use it in GitHub Desktop.
Save phense/00e53ab912d504205a9454aca8766a2f to your computer and use it in GitHub Desktop.
ahk-snippets #code
#Persistent ; Use this directive to prevent the script from exiting after the auto-execute
; section (top part of the script) completes. This is useful in cases where a
; script contains timers and/or custom menu items.
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
F9::
Stop := 0
Loop {
Gosub, ButtonSequence ; execute the button-press sequence
Random, TimeToWait, 240000, 600000 ; Get a random number between 4 and 10 minutes (measured in miliseconds)
; 240000, 600000
Sleep, %TimeToWait% ; wait for random time
} Until Stop
return
ButtonSequence: ;Function called by SetTimer
SendInput 1
Random, Sleeptime, 1000, 2500
Sleep %Sleeptime%
SendInput 2
Random, Sleeptime, 1000, 3000
Sleep %Sleeptime%
SendInput 3
Random, Sleeptime, 1000, 4000
Sleep %Sleeptime%
SendInput 4
return
F10::Stop := 1 ; Stop Script by pressing F10
;; example of basics
#c::
if (winc_presses > 0) ; SetTimer already started, so we log the keypress instead.
{
winc_presses += 1
return
}
; Otherwise, this is the first press of a new series. Set count to 1 and start
; the timer:
winc_presses := 1
SetTimer, KeyWinC, -400 ; Wait for more presses within a 400 millisecond window.
return
KeyWinC:
if (winc_presses = 1) ; The key was pressed once.
{
Run, m:\ ; Open a folder.
}
else if (winc_presses = 2) ; The key was pressed twice.
{
Run, m:\multimedia ; Open a different folder.
}
else if (winc_presses > 2)
{
MsgBox, Three or more clicks detected.
}
; Regardless of which action above was triggered, reset the count to
; prepare for the next series of presses:
winc_presses := 0
return
F9:: ; Start script by Pressing F9
stop := 0
Loop
{
Send {d down} ; Press down and hold a for 2 seconds
Sleep 2000
Send {d up}
Sleep 300000 ; Wait 5 minutes (300.000 ms)
}until Stop
return
F10::Stop := 1 ; Stop Script by pressing F10
F9::
ToggleKey := !ToggleKey ; variable is either 1 or 0. gets switched ever time you press
; the F9 key, therefore 'making' it act like a toggle
if (ToggleKey) {
SendInput 4 ; 'Press' 4
SendInput 3 ; 'Press' 3
SetTimer, RepeatKey3, 12300 ; Repeat Function-call every 12.3s
SetTimer, RepeatKey4, 4300
}
else {
SetTimer, RepeatKey3, Off ; stop timer
SetTimer, RepeatKey4, Off
}
return
RepeatKey3: ;Function called by SetTimer
SendInput 3 ; 'Press' 3
return
RepeatKey4:
SendInput 4 ; 'Press' 4
return
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment