在 Autohotkey 中发送用两个变量包裹的剪贴板内容

Send clipboard content wrapped with two variables in Autohotkey

使用 Autohotkey,我想连接变量 1、剪贴板内容和变量 2。

例如,如果:

  1. 变量1 = https://example.com/somepage.php?command=details&reservationId=
  2. 剪贴板内容 = 12345
  3. 变量2 = &url=%2Fsomepage.php%3submit%3DSEARCH%26submit

预期结果为:

https://example.com/somepage.php?command=details&reservationId=12345&url=%2Fsomepage.php%3submit%3DSEARCH%26submit


下面显示的两种方法只是输出12345

我做错了什么?

尝试 1:

::hd-eurl::
 ClipSaved := ClipboardAll       ; get clipboard
 variable1:= "https://example.com/somepage.php?command=details&reservationId="
 variable2:= "&url=%2Fsomepage.php%3submit%3DSEARCH%26submit"
 ClipNew =  %variable1% . ClipSaved . %variable2%
 clipboard = ClipNew 
 ClipWait
 Send, ^v
 clipboard := ClipSaved       ; restore original clipboard
 return

尝试 2:

::hd-eurl::
 Send ^c
 ClipSaved := ClipboardAll       ; get clipboard
 variable1= https://example.com/somepage.php?command=details&reservationId=
 variable2= &url=`%2Fsomepage.php`%3submit`%3DSEARCH`%26submit
 ClipNew =  variable1 . ClipSaved . variable2
 clipboard = ClipNew 
 ClipWait
 Send, ^v
 clipboard := ClipSaved       ; restore original clipboard
 return

更新(相同结果):

::hd-eurl::
 ClipSaved := ClipboardAll       ; get clipboard
 variable1:= "https://example.com/somepage.php?command=details&reservationId="
 variable2:= "&url=%2Fsomepage.php%3submit%3DSEARCH%26submit"
 ClipNew :=  variable1 . ClipSaved . variable2
 clipboard := ClipNew 
 ClipWait
 Send, ^v
 clipboard := ClipSaved       ; restore original clipboard
 return

工作解决方案

这就是我最终让它工作的方式。不过选答案中Blauhirn的方法用起来简单多了。

::hd-eurl::
 ClipSaved := ClipboardAll       ; store clipboard backup 
 variable1:= "https://example.com/somepage.php?command=details&reservationId="
 variable2=  %ClipBoard%
 ClipBoard =
 variable3:= "&url=%2Fsomepage.php%3submit%3DSEARCH%26submit"
 variable4:=  variable1 . variable2 . variable3
 Clipboard:= variable4
 ClipWait 
 Send, ^v
 Clipboard := ClipSaved       ; restore original clipboard
 return

正确的语法是

ClipNew :=  variable1 . ClipSaved . variable2

ClipNew =  %variable1%%ClipSaved%%variable2%

Variables and expressions

也修改这一行

clipboard := ClipNew

您的 clipSaved 变量包含 clipboardAllDocumentation 说:

Variables to which ClipboardAll has been assigned are in binary format and thus will appear as gibberish when displayed with MsgBox or similar.

分配给 clipNew 时,您必须使用 clipboard,例如

 ClipNew := variable1 . clipboard . variable2

除此之外,我建议你根本不要修改clipboard的内容,因为这是最复杂的方法。如果你想发送一些东西,只需在字符串上使用 send command 而不是调用 CTRL+V:

::hd-eurl::
    variable1:= "https://example.com/somepage.php?command=details&reservationId="
    variable2:= "&url=%2Fsomepage.php%3submit%3DSEARCH%26submit"
    send % variable1 clipboard variable2
return