I\'m new to writing my own AutoHotKey scripts so this just has to be something stupid I\'m missing here.
The intent of the script is for the user to select some text
When you have a script that behaves sporadically, and/or differently in other programs,
the first thing to try is simulating a key-press duration and/or delay period between keys.
This is because some programs aren't designed to handle the speed that AutoHotkey sends
artificial keystrokes.
Here is the most basic example:
f1::
Send, {ctrl down}
Sleep, 40
Send, {c down}
Sleep, 40
Send, {c up}
Sleep, 40
Send, {ctrl up}
Return
We have several ways to make it more concise.
The easiest (yet not always desirable since it blocks during delays, unlike sleep)
is the SetKeyDelay command, which only works for the SendEvent and SendPlay modes.
f2::
SetKeyDelay, 40 ; could be set at the top of the script instead.
Send, {ctrl down}{c down}{c up}{ctrl up}
Return
Those using AHK_L can make use of a for-loop and an array:
f3::
For i, element in array := ["{ctrl down}","{c down}","{c up}","{ctrl up}"] {
Sendinput, %element%
Sleep, 40
} Return
And those using AHK basic (or AHK_L) can use Loop, Parse
:
f4::
list := "{ctrl down},{c down},{c up},{ctrl up}"
Loop Parse, list, `,
{
Sendinput, %A_LoopField%
Sleep, 40
} Return
It's useful to read about the three Sendmodes.
More information can be found at the bottom of the Send command's page.