1
votes

I want a script that will press a button once, and then wait 3 seconds, before allowing it to be pressed again in AutoHotKey.

I use F3 to send to send Q and {F3}.

$F3::
Send q
Send {F3}
return

However, I hold down F3 to send Q repeatedly, but I only want {F3} to be sent after waiting at least 3 seconds before it was last sent.

If you still don't understand:

(Holds F3) Send q Send F3 Send q Send q Send q (3 seconds have passed) Send F3 Send q Send q

Thanks in advance.

2

2 Answers

0
votes

You want to remap the key for those 3 seconds to only send q, then re-enable it. You can do this with Hotkey, *F3, off. Look here

Here is what you want F3 to do:

F3 Mode 1

  1. Remap F3 to q
  2. Sleep for 3 seconds
  3. Send F3
  4. Reamap F3 to F3 Mode 1 (ie this same function)
0
votes

I tried implementing my first solution, but wasn't able to get it to work. It seems that the dynamic remapping doesn't get installed right away. Below is a simpler solution, which uses the time of the last F3 keypress. Note that since you are sending {F3}, you need to temporarily disable the F3 binding, or else it will fire the action again.

last_f3_time := 0

F3_Mode_1()
{
   global last_f3_time
   Send q
   now := A_TickCount

   if (now - last_f3_time > 3000)
   {
      last_f3_time := now
      Hotkey, F3, off
      Send {F3}
      Hotkey, F3, on
   }
   ;else{MsgBox, Too early! %now%}
}


F3::F3_Mode_1()