AHK Prevent Multiple Hotkey Triggers - triggers

It's a quite simple code.
I just want my Mousewheeldown to Send P only once.
Even if I scroll it like 3 times, I only want it to send P only once every 100ms or sth.
Here is my really small bit of code so far:
SetKeyDelay , -1, 50
#NoTrayIcon
#NoEnv
#persistent
#MaxMem 2
WheelDown::
Send {p}
return

Sleeping a bit after sending the keystroke would solve this problem.
WheelDown:
Send, p
Sleep, 100
return
Also, you do not need to put the p between {}-s (curly braces), as it is not a special key.
The sleep command takes it's parameter as milliseconds, so if for example you would want to allow it only one 'p' in a second, you would write Sleep, 1000.

Related

AutoHotKey, Repeat key press

All I want is a simple keypress of lowercase "v" 4 times with a 1 second delay between. I have tried so many iterations of this simple-sounding action to no avail and the most infuriating thing is that I can get it to work with a capital "V" – but that also emulates a shift+v key press. I just don't understand.
v::
Loop, 4
{
sleep 10
SendInput {V} ; capital V works perfectly fine but includes Shift+v, I don't want a shift
sleep 1000
}
return
Whereas ...
v::
Loop, 4
{
sleep 10
SendInput {v} ; Lowercase v, Does absolutely nothing...
sleep 1000
}
return
What am I missing?
Try
$v::
Loop, 4
{
sleep 10
SendInput v
sleep 1000
}
return
The $ prefix works by forcing the keyboard hook to be used and prevents the Send command from triggering the hotkey itself.
Alternative #UseHook can be specified somewhere above, so the keyboard hook is implemented for every hotkey after it
Another solution:
#IfWinActive ahk_class your_app_ahk_class
$v::
SetKeyDelay, 1000
Send {v 4}
Return
I don't know what's the purpose of this, but since the shortcut does not include any control keys, it might be better to limit this to a specific app. The first line in my snippet tries to achieve this.

I want to simply make a script for send "arrow right" in autohotkey

I want to simply make a script for send "2x arrow right" in autohotkeys. I now have:
^Tab::
Send,
return
After Send, I tried several combinations, some of them being {right}, {Right}, plus over 10 more combinations I found on the net which supposed to perform the difficult task of arrow right, but none which managed to work. Only thing I want is to Send, [insert some words which will do the trick] to have autohotkeys perform "2x arrow right". Would make my life a lot easier during programming. Who can help me out?
No need for Return for single-line statements. Keys can be repeated as so:
^Tab::SendInput {Right 2}
See more about repeating keys with Send[Raw|Input|Play|Event] and about using SendInput instead of Send here: https://www.autohotkey.com/docs/commands/Send.htm#SendInputDetail
Switched from Send to SendInput for reliability.
The easiest way to solve this would just be to make your script send two SendInput, {right} one after another.
For Example:
^Tab::
SendInput, {right}
SendInput, {right}
return
If you needed it to loop a finite number of times, you could use this instead:
^Tab::
Loop 2 ;replace '2' with however many times you want the next line to repeat
SendInput, {right}
return
Sidenote: In the context that I am using it, return just means to stop executing a multi-line hotkey. What your example above does is send the word "return". If you want to send a special key like the right arrow button or the return/enter key, you would have to enclose it in curly braces {}. For example, {right} or {return} corresponding to the aforementioned examples. For more information about this, please see this documentation link.

How do I add a delay between SendInput commands in AutoHotkey?

I have an AutoHotkey script using SendInput which sends MouseClick commands too quickly for my program to handle. My script will send a MouseClick to focus an input field, then start typing before the field finishes focusing.
I've tried using SetKeyDelay to make my script run a bit slower, but this doesn't work with SendInput.
Note: SetKeyDelay is not obeyed by SendInput; there is no delay between keystrokes in that mode. This same is true for Send when SendMode Input is in effect.
Documentation for SetKeyDelay
My current workaround is to use sleep commands after each input, but this is less than ideal.
SendMode Input
F1::
MouseClick, left, 61, 50 ; select title field
sleep 100 ; artificial delay to prevent misfocused inputs
SendInput %user_input%{Enter} ; enter job title
sleep 100 ; artificial delay
MouseClick, left, 67, 408 ; select job
sleep 100 ; artificial delay
Return
Ideally I would like a more elegant solution for adding a delay between each SendInput command without manually using a sleep command each time.
How can I add a delay between SendInput commands in AutoHotkey without repeatedly using sleep?
Try using SendPlay instead of SendInput.
This sends text and mouse clicks with a 100ms delay following each click
user_input := "hello world"
SetMouseDelay 100, Play
SendPlay {Click 61,50}%user_input%{enter}{click 67,408}
From the documentation for SendPlay.
SendPlay
Note: SendPlay may have no effect at all if UAC is enabled, even if the script is running as an administrator. For more information, refer to the FAQ.
Like SendInput, SendPlay's keystrokes do not get interspersed with keystrokes typed by the user. Thus, if the user happens to type something during a SendPlay, those keystrokes are postponed until afterward.
Although SendPlay is considerably slower than SendInput, it is usually faster than the traditional SendEvent mode (even when KeyDelay is -1).
SendPlay does not use the standard settings of SetKeyDelay and SetMouseDelay. Instead, it defaults to no delay at all, which can be changed as shown in the following examples:
SetKeyDelay, 0, 10, Play ; Note that both 0 and -1 are the same in SendPlay mode.
SetMouseDelay, 10, Play

Simple keypress script with loop in Autohotkey

Whenever you press w you get into a loop that press e around every 10 seconds. Another button has to be pressed to get out of it again at any moment (and making it possible to start over again). This is what I have so far:
w::
Loop
{
Send, e
Random, SleepAmount, 9000, 10000
Sleep, %SleepAmount%
x::Break
}
Return
I don't understand why it is not working yet. It presses e once and doesn't do anything anymore after that.
x::Break
is the short form for
x::
break
return
and therefore terminates the current subroutine. Never define a hotkey within any other execution bodies. Instead, define the x-hotkey outside the w hotkey and make it stop the loop.
Example using goTo (note that goSub is different for the latter will not terminate the subroutine):
w::
Loop {
send e
Random, SleepAmount, 9000, 10000
Sleep, %SleepAmount%
}
after_loop:
return
x::
goTo after_loop
return
; or, more compact:
; x::goto after_loop
Since gotos are pretty bad programming style, you might consider using a timer (instead of the loop). But to be honest, it's not worth it because your sleep amount is not fix.

Autohotkey: I'm unable to make a script for pressing 2 keys with a delay beteween them

Well i want to make a script with the objetive:
3{DOWN} key, and later hold or quickly press Z x3, and loop all that.
I have been trying to work with loop command but i just can't, im new with AutoHotkey and english it's not my native languague so it's been pretty hard.
Here is the code i tried but didn't work as i expect, since it press Z before the 3 {DOWN} keys.
#Persistent
SetTimer, Code, 150
Return
Code:
Send, Z{DOWN}
Return
If you know anyway to improve what i'm doing like, add a toggle like F8 to turn on/off, it would be aweosome.
Thanks for any help.
Helena.
Helena, What your script does right now is the following. As soon as the script starts it will start to send [Z] and [Arrow down] every 150 mili seconds. This is independent of what application is running at that time.
You write that you want to loop sending codes and that you want to toggle this ON/OFF.
Here is an example that comes closer to your goal.
#Persistent
F8:: ; This is your [F8] Toggle hotkey
If Toggle:=!Toggle ; Here you "test" the value of the variable "toggle" and after testing switch it to the opposite (true/false)
SetTimer, Trigger, -1 ; This is to create a separate thread for the loop. -1 means start in 1 ms but only do this one time, not every 1 ms's.
return
Trigger:
While (Toggle)
{
Send, +z{Down} ; + is the shift key, thus +z makes captial Z
Sleep, 500 ; Wait 500 ms (1/2 a second)
Send, +{z Down} ; Press Shift z Down. This will NOT start a repeat like ZZZZZZZZZZZZZZZZ
Sleep, 500 ; Wait 500 ms (1/2 a second)
Send, +{z Up} ; Lift Shift z Up
Sleep, 1 ; Required. Without it The F8 keypress to toggle off can not be read anymore
}
Return