Reputation: 2485
What I want to do is to build a function, that I can use to paste something (in this case URLs). Normally I would just use the send command or the sendinput command, but they are kind of slow which is a little bit annoying. That's why I want to avoid it and use the clipboard instead.
Here my function:
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
}
Here how I'm using the function:
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
Then when I'm trying to use the function. I get an error: Error: The following variable name contains an illegal character: "chrome://settings/content/images" Line: -->1934: Clipboard := %CustomClip%
What am I doing wrong here?
Upvotes: 0
Views: 66
Reputation: 10568
You get this error message because
Variable names in an expression are NOT enclosed in percent signs.
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
Upvotes: 2