转义右花括号时出现问题 [AHK 1.1.30.03]

问题描述 投票:0回答:1

在这个 AutohotKey 脚本(AHK 版本 1.1.30.03)中,我想在剪贴板中保存一段代码并通过执行 Ctrl + V 进行粘贴。

我遇到的问题是,从最后一个 if 语句的最后一个右大括号开始,AHK 将文本解释为代码而不是纯文本。 (见附图)。

我已尝试按照文档中的说明通过在前面添加反引号来转义所述大括号,但它不起作用`}https://www.autohotkey.com/docs/v1/misc/EscapeChar.htm)。我也尝试过使用双右大括号来逃避它,但这也不起作用}}

我指出的语法错误

AHK 代码脚本

^*!p::
ClipboardBackup:=ClipboardAll 
Clipboard =
(
    if (typeof jQuery === 'undefined') {
        console.error('some error');
    } else {
        function handleComponentClick(event) {
            if (event.ctrlKey) {
                event.stopPropagation();
                let target = jQuery(event.target);
                if (!target.is('[data-sap-ui]')) {
                    target = target.closest('[data-sap-ui]');
                }
                if (target.length) {
                    console.log("%c ID clicked: %c" + target.attr('id') || 'ID dont found',
                        "background:MediumAquaMarine; color:black; font-size: 0.8rem; padding: 2px 0; border-radius: 2px;font-weight: bold;",
                        "background:white; color:black; font-size: 0.8rem; padding: 2px 5px; border-radius: 2px;"
                    );
                }
            }
        }

    } ;Else close curly brace
)
ClipWait, 2
SendInput, ^v
sleep, 50 
Clipboard:=ClipboardBackup 
return

谢谢, 霍托莫尔

autohotkey
1个回答
0
投票

百分号必须是 转义,并且第 19 行的括号也必须是,因为脚本将其解释为必须复制的文本的结尾:

^*!p::
ClipboardBackup:=ClipboardAll 
Clipboard =
(
    if (typeof jQuery === 'undefined') {
        console.error('some error');
    } else {
        function handleComponentClick(event) {
            if (event.ctrlKey) {
                event.stopPropagation();
                let target = jQuery(event.target);
                if (!target.is('[data-sap-ui]')) {
                    target = target.closest('[data-sap-ui]');
                }
                if (target.length) {
                    console.log("`%c ID clicked: `%c" + target.attr('id') || 'ID dont found',
                        "background:MediumAquaMarine; color:black; font-size: 0.8rem; padding: 2px 0; border-radius: 2px;font-weight: bold;",
                        "background:white; color:black; font-size: 0.8rem; padding: 2px 5px; border-radius: 2px;"
                    `) ;
                }
            }
        }

    } ;Else close curly brace
)
ClipWait, 2
SendInput, ^v
sleep, 50 
Clipboard:=ClipboardBackup 
return
© www.soinside.com 2019 - 2024. All rights reserved.