AutoHotKey strange issue with Copy (Ctrl-C) every other execution

懵懂的女人 提交于 2019-12-01 18:10:13

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.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!