Skip to content

Instantly share code, notes, and snippets.

@HamousOnWheels
Last active February 26, 2022 16:42
Show Gist options
  • Select an option

  • Save HamousOnWheels/5ec1e45e1f2053c0edb695a806643557 to your computer and use it in GitHub Desktop.

Select an option

Save HamousOnWheels/5ec1e45e1f2053c0edb695a806643557 to your computer and use it in GitHub Desktop.
Autohotkey function that replicates Photoshop's spring loaded keys for any key. Makes a toggle temporary if key is held, or permanent if key is tapped.
; Replicates spring loaded key functionality for any key
SpringLoadedKey(key, timeHeld) ; parameters: hotkey that you want to send, timeout for the key to be considered held and not tapped
{
send { %key% } ; send first hotkey on key down
keywait, %A_ThisHotkey% ; wait for key up
if (A_TimeSinceThisHotkey > timeHeld) ; if key was down for more than the timeout value,
{ ; then on key up send the second hotkey to toggle it off,
send { %key% } ; otherwise do nothing, making the toggle 'stick'
}
}
; Call the function with something like
#IfWinActive ahk_exe Photoshop.exe
x::SpringLoadedKey("x", 500) ;spring loaded key for switching btw foreground and background colours
; set the timeout value as required. I believe Photoshop's is 500 ms
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment