1

我试图让 Autokey 像 Autohotkey 在 Windows 中为我工作一样工作。

可以在 Autohotkey 中设置的一个非常有用的功能是分配一个键盘键来抓取突出显示的文本,然后转到 url,抓取该 url,然后将突出显示的文本和 URL 插入到预定短语中的特定位置。

使用不同格式的链接创建文本非常有用。

我所描述的 Autohotkey 脚本看起来像这样:

insert::
clipboard =
Send, ^c
ClipWait
myText = %clipboard%
Send, !d
clipboard =
Send, ^c
ClipWait
myURL = %clipboard%
myLink = <a href="%myURL%">%myText%</a>
clipboard = %myLink%
return

有没有办法将其转换为有效的 Autokey 脚本?

4

1 回答 1

1
# assigning a keyboard key to
# `hotkey - a key or combination of keys that, when pressed, will trigger AutoKey to do something; run a script, insert a phrase or display a menu. A hotkey can be created using any key on the keyboard (within reason), with or without one or more modifier keys. The modifier keys are Shift, Control, Alt and Super (a.k.a. Windows).`
# [Guide](https://github.com/autokey/autokey/wiki/Beginners-Guide)

import os, time

# grab highlighted text
myText = clipboard.get_selection()

# then go to url
myCmd = "/usr/bin/firefox --new-window http://www. your site .biz/"
os.system(myCmd)
time.sleep(0.25)

# grab that url, and then
keyboard.send_keys('<F6>')
time.sleep(0.25)
myURL = clipboard.get_selection()

# insert the highlighted text and URL in specific places within a predetermined phrase.
# run a window wait, then paste the texts there. Following example opens a msgbox2sec.ahk (create it first):
myCmd = 'wine ~/.wine/drive_c/Program\ Files/AutoHotkey/AutoHotkey.exe /home/administrator/Desktop/msgbox2sec.ahk'
os.system(myCmd)
time.sleep(0.25)

active_class = window.get_active_class()
if not active_class == "your class name":  # for example: "autokey-gtk.Autokey-gtk":
    time.sleep(0.25)  # sleep longer

myLink = "<a href = \"" + myURL + "\">" + myText + "</a>"
# paste your link, then copy it:
keyboard.send_keys(myLink)

# select select a line:
keyboard.send_keys('<home>')
keyboard.send_keys("<shift>+<end>")

# copy line to clipboard:
keyboard.send_keys('<ctrl>+c')

# or copy line to variable:
c = clipboard.get_selection()
于 2020-09-01T11:47:13.297 回答