AutoHotKey每隔一次执行复制(Ctrl-C)的奇怪问题 [英] AutoHotKey strange issue with Copy (Ctrl-C) every other execution

查看:364
本文介绍了AutoHotKey每隔一次执行复制(Ctrl-C)的奇怪问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚开始编写自己的AutoHotKey脚本,因此这只是我在这里所缺少的愚蠢之举.

I'm new to writing my own AutoHotKey scripts so this just has to be something stupid I'm missing here.

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

The intent of the script is for the user to select some text and press the hot-key (Win-W). The menu pops-up and they click the menu item. The selected text should then be copied to the clipboard. That's all i'm trying to do right now.

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

The problem is that it works the first time, then fails, then works, then fails, etc. It basically only works every other time.

我正在使用最新的AutoHotKey_l(Unicode 32位)运行Win7 x64.

I'm running Win7 x64 with the latest AutoHotKey_l (unicode 32bit).

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

I have a timeout on the ClipWait, and it basically just waits, never receives the copied text, and issues an 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.

任何帮助将不胜感激.

推荐答案

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

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.

这是最基本的示例:

f1::
Send, {ctrl down}
Sleep, 40
Send, {c down}
Sleep, 40
Send, {c up}
Sleep, 40
Send, {ctrl up}
Return

我们有几种方法可以使其更简洁.
最简单的(但并非总是理想的,因为它在延迟过程中会阻塞,与睡眠不同)
SetKeyDelay 命令,仅适用于SendEvent和SendPlay模式./p>

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 

使用AHK_L的用户可以使用for循环和数组:

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

使用AHK basic(或AHK_L)的用户可以使用Loop, Parse:

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.

这篇关于AutoHotKey每隔一次执行复制(Ctrl-C)的奇怪问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆