AutoHotKey奇怪的问题与复制(Ctrl-C)每隔一次执行

kma*_*man 5 autohotkey

我刚开始编写自己的AutoHotKey脚本,所以这只是我在这里缺少的傻事.

脚本的目的是让用户选择一些文本并按热键(Win- W).弹出菜单,然后单击菜单项.然后应将所选文本复制到剪贴板.这就是我现在正在努力做的事情.

问题是它第一次工作,然后失败,然后工作,然后失败等等.它基本上只在每隔一段时间工作.

我用最新的AutoHotKey_l(unicode 32bit)运行Win7 x64 .

我有一个超时ClipWait,它基本上只是等待,从未收到复制的文本,并发出ErrorLevel 1.

这是代码:

#SingleInstance force
; EXAMPLE #2: This is a working script that creates a popup menu that is displayed when the user presses the Win-w hotkey.

; Create the popup menu by adding some items to it.
Menu, MyMenu, Add, Demo, Demo

return  ; End of script's auto-execute section.

Demo:
clipboard =  ; Start off empty to allow ClipWait to detect when the text has arrived.
Send ^c
ClipWait, 2  ; Wait for the clipboard to contain text.
if ErrorLevel = 1
{
    MsgBox Copy failed
}
else
{
    MsgBox Copy worked
}
return

#w::Menu, MyMenu, Show  ; i.e. press the Win-w hotkey to show the menu.
Run Code Online (Sandbox Code Playgroud)

任何帮助将不胜感激.

Hon*_*Abe 7

如果脚本在其他程序中偶尔出现和/或行为不同,
首先要尝试模拟按键之间的按键持续时间和/或延迟时间.
这是因为某些程序不是为了处理AutoHotkey发送
人工击键的速度而设计的.

这是最基本的例子:

f1::
Send, {ctrl down}
Sleep, 40
Send, {c down}
Sleep, 40
Send, {c up}
Sleep, 40
Send, {ctrl up}
Return
Run Code Online (Sandbox Code Playgroud)

我们有几种方法可以使它更简洁.
最简单(但并不总是令人满意,因为它在延迟期间阻塞,与睡眠不同)
SetKeyDelay命令,它仅适用于SendEvent和SendPlay模式.

f2::
SetKeyDelay, 40 ; could be set at the top of the script instead.
Send, {ctrl down}{c down}{c up}{ctrl up}
Return 
Run Code Online (Sandbox Code Playgroud)

那些使用AHK_L的人可以使用for循环和数组:

f3::
For i, element in array := ["{ctrl down}","{c down}","{c up}","{ctrl up}"] {
   Sendinput, %element%
   Sleep, 40
} Return
Run Code Online (Sandbox Code Playgroud)

那些使用AHK basic(或AHK_L)的人可以使用Loop, Parse:

f4::
list := "{ctrl down},{c down},{c up},{ctrl up}"
Loop Parse, list, `,
{
    Sendinput, %A_LoopField%
    Sleep, 40
} Return 
Run Code Online (Sandbox Code Playgroud)

阅读有关三个Sendmodes的内容非常有用.
可以在Send命令页面的底部找到更多信息.