If you’ve ever used Microsoft Word or Windows Live Writer, you’re probably familiar with how you can highlight some text and then use the Ctrl+K keyboard shortcut to convert that text into a hyperlink. If you’re in a text editor, it’s not quite that easy… until now.
如果您曾经使用过Microsoft Word或Windows Live Writer,则可能熟悉如何突出显示某些文本,然后使用Ctrl + K键盘快捷键将该文本转换为超链接。 如果您在文本编辑器中,那么并不是那么容易……直到现在。
What we’ve done is put together an AutoHotkey script that automates the process of creating a link, and we’ll demonstrate it using the WordPress post editor, though that’s not the only place you could use this technique.
我们所做的是将一个AutoHotkey脚本放在一起,该脚本可以自动创建链接,并且我们将使用WordPress帖子编辑器对其进行演示,尽管这不是您唯一可以使用此技术的地方。
Using Our New “Insert Hyperlink” Feature
使用我们的新“插入超链接”功能
First we’ll assume that you’ve already copied the URL to the clipboard, and then you will simply select some text that you want to turn into a link—assuming you are in the HTML view, of course, since you wouldn’t want to do this in the visual editor.
首先,我们假设您已经将URL复制到剪贴板,然后您只需选择一些要转换为链接的文本,当然,假设您处于HTML视图中,因为您不会想在视觉编辑器中做到这一点。
![image image](https://i-blog.csdnimg.cn/blog_migrate/45c44bfde227e5e51349517191fb71e5.png)
Now you’ll press the shortcut key that you’ve chosen—for our example, we’re using Alt+9 since that’s rarely taken by anything else…
现在,您按选择的快捷键-在我们的示例中,我们使用的是Alt + 9,因为这很少被其他任何东西所接受…
![image image](https://i-blog.csdnimg.cn/blog_migrate/a354d149a59975a2629d53721c696da5.png)
And just like that, the text is replaced with the hyperlink including the URL you had on the clipboard.
就像这样,文本将替换为超链接,其中包括您在剪贴板上拥有的URL。
Note: Of course, in the WordPress editor, you could always use the Alt+Shift+A shortcut key instead, which would launch a dialog allowing you to enter the link, but we’re just using this as an example—though you might note that our method requires only a single keystroke.
注意:当然,在WordPress编辑器中,您始终可以使用Alt + Shift + A快捷键来代替,这将启动一个对话框,允许您输入链接,但是我们仅以此为例,尽管您可以请注意,我们的方法只需要一个按键。
![image image](https://i-blog.csdnimg.cn/blog_migrate/a51a8166a2b8591d41e799e211977ea5.png)
Creating the “Insert Hyperlink” Feature
创建“插入超链接”功能
To create the feature for yourself, either create a new AutoHotkey script, add the following to your existing script, or download the file at the bottom and run it. Naturally we’re assuming you already have AutoHotkey installed.
要为自己创建功能,请创建一个新的AutoHotkey脚本,将以下内容添加到现有脚本中,或者在底部下载文件并运行它。 当然,我们假设您已经安装了AutoHotkey 。
!9::{ Sleep, 100 clipurl := clipboard Send ^c Sleep, 50 clipurl := "<a href=""" . clipurl . """>" . clipboard . "</a>" SendInput {Raw}%clipurl% clipboard := clipurl clipurl =; Return}
!9 :: {睡眠,100个clipurl:=剪贴板发送^ c睡眠,50个clipurl:=“ <a href =”“”。 clipurl。 “”“>”。 剪贴板 。 “ </a>” SendInput {原始}%clipurl%剪贴板:= clipurl clipurl =; 返回}
Here’s how it works… you’ll notice that we’re using Alt+9 as our keyboard shortcut, but you can customize this to anything else you’d like.
它的工作原理如下:您会注意到我们使用Alt + 9作为键盘快捷键,但是您可以根据自己的喜好对其进行自定义。
The first line inside the brackets pauses the script for 1/10th of a second to make sure that you’ve released the shortcut key, then the clipurl := clipboard line copies the current clipboard (the URL) into a variable to save for later. Once that’s done, the script automates copying the selection to the clipboard with Ctrl+C, assembles the link together, and then pastes the whole thing back into the application, replacing the current text in the process. The last step puts the clipboard back to the way it was before you ran the command.
括号内的第一行将脚本暂停1/10秒,以确保您已释放快捷键,然后clipurl:=剪贴板行将当前剪贴板(URL)复制到变量中,以备后用。 完成此操作后,脚本会自动使用Ctrl + C将选择内容复制到剪贴板,将链接组装在一起,然后将整个内容粘贴回应用程序中,以替换过程中的当前文本。 最后一步将剪贴板恢复到运行命令之前的状态。
Download the “Insert Hyperlink” AutoHotkey Script