【问题标题】:AutoHotkey - Building a Clipboardsaving FunctionAutoHotkey - 构建剪贴板保存功能
【发布时间】:2019-11-24 15:29:46
【问题描述】:

我想做的是构建一个函数,我可以用它来粘贴一些东西(在本例中是 URL)。通常我只会使用 send 命令或 sendinput 命令,但它们有点慢,有点烦人。这就是为什么我想避免它并改用剪贴板。

这是我的功能:

ClipPaster(CustomClip){
        ClipSaved := ClipboardAll ;Saving the current clipboard
        Clipboard := %CustomClip% ;Overwriting the current clipboard
        Send, ^{v}{Enter} ;pasting it into the search bar
        Clipboard := Clipsaved ;Recovering the old clipboard
    }   

我是如何使用这个函数的:

RAlt & b::
   Send, ^{t} ;Open a new tab
   ClipPaster("chrome://settings/content/images") ;Activating my clipboard   
   return
RAlt & g::
   Send, ^{t} ;Open a new tab
   ClipPaster("https://translate.google.com/#en/es/violin") ;Activating 
   my clipboard function
   return

然后当我尝试使用该功能时。我收到一个错误: 错误:以下变量名称包含非法字符:“chrome://settings/content/images” 线: -->1934: 剪贴板:= %CustomClip%

我在这里做错了什么?

【问题讨论】:

    标签: function variables autohotkey clipboard


    【解决方案1】:

    您收到此错误消息是因为

    表达式中的变量名不用百分号括起来。

    https://www.autohotkey.com/docs/Variables.htm#Expressions

    ClipPaster(CustomClip){
            ClipSaved := ClipboardAll  ; Saving the current clipboard
            Clipboard := ""            ; empty the clipboard (start off empty to allow ClipWait to detect when the text has arrived)
            ; Variable names in an expression are NOT enclosed in percent signs:
            Clipboard := CustomClip    ; Overwriting the current clipboard 
            ClipWait 1                 ; wait max. 1 second for the clipboard to contain data
            if (!ErrorLevel)           ; If NOT ErrorLevel clipwait found data on the clipboard
                Send, ^v{Enter}        ; pasting it into the search bar
            Sleep, 300
            Clipboard := Clipsaved     ; Recovering the old clipboard
            ClipSaved := ""            ; Free the memory
        }
    

    https://www.autohotkey.com/docs/misc/Clipboard.htm#ClipboardAll

    【讨论】:

    • 好的,有道理!我试图在没有睡眠时间的情况下做到这一点,但由于某种原因这不起作用。随着睡眠时间它完美地工作!谢谢user3419297:D
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-14
    • 2012-08-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多