Hold to activate macro Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
CaseyMoon
Posts: 5
Joined: 25 Mar 2024, 08:22

Hold to activate macro

Post by CaseyMoon » 25 Mar 2024, 08:27

Code: Select all

Mbutton::
   SetTimer, ButtonHeld, 2000
   return

Mbutton up::
   SetTimer, ButtonHeld, Off
   return
 
ButtonHeld:
   ; Add whatever you want to trigger if button held for 2 seconds here
   Send Hello World
   return
Hi! I found this old script and it works perfectly for what I want to do, but I want to change the "Mbutton" (middle mouse button) to for example the "F" key. When I change it, it doesn't work. How can I fix this? Thanks in advance!

User avatar
mikeyww
Posts: 27006
Joined: 09 Sep 2014, 18:38

Re: Hold to activate macro  Topic is solved

Post by mikeyww » 25 Mar 2024, 08:46

Welcome to this AutoHotkey forum!

Instead of posting your working scripts, post the scripts that do not work!

Code: Select all

#Requires AutoHotkey v1.1.33.11

$f::
SetTimer ButtonHeld, 2000
SoundBeep 1500
KeyWait f
SetTimer ButtonHeld, Off
SoundBeep 1000
Return

ButtonHeld:
Send Hello World
Return
If you are new to AHK, I recommend using its current version, which is v2, instead of this older deprecated version that is no longer developed.

Code: Select all

#Requires AutoHotkey v2.0

$f:: {
 SetTimer buttonHeld, 2000
 SoundBeep 1500
 KeyWait 'f'
 SetTimer buttonHeld, 0
 SoundBeep 1000
}

buttonHeld() {
 SendEvent 'Hello World'
}

CaseyMoon
Posts: 5
Joined: 25 Mar 2024, 08:22

Re: Hold to activate macro

Post by CaseyMoon » 25 Mar 2024, 09:56

Works as intended. Thank you!

Post Reply

Return to “Ask for Help (v1)”