支援Unicode的Autohotkey終於浮上抬面!

因為重新安裝家用舊的HP筆電,在下載Autohotkey時發現Unicode的版本已經出現在官方下載網頁裡了!原來這個Unicode版本是由Lexikos開發的分支,其開發沿革在這篇AutoHotkey_L:支持unicode, 能?送中文的AutoHotkey分支有詳細的介紹,它的說明文件可由此處瀏覽。

以下我寫了幾個簡單的中文輸出測試。不必再用剪貼簿來處理中文,真是簡單很多。

  • send_brackets函數能將選取的文字或剪貼簿內容的前後加上不同的中文括號,例如《書名號》、【中括號】等。
  • send_html則是輸出常用的HTML標籤,會判斷剪貼簿內容是否為網址而輸出到不同的插入點。
  • send指令以sendInput取代,輸出速度提升不少
;; 傳回選取文字的內容
getSelectedText() {
   clpb_saved = %ClipboardAll% ; save clipboard
   Clipboard := "" ; clear
   Send, ^c ; simulate Ctrl+C (=selection in clipboard)
   selection = %Clipboard% ; save the content of the clipboard
   Clipboard = %clpb_saved% ; restore old content of the clipboard
   return selection
}

;; 送出一組中文符號,如send_brackets("「」")
send_brackets(symbol) {
  selection := getSelectedText()
  StringLen, length, selection
  if (length = 0) {
    selection = %clipboard%
  }
  ;; msgBox %selection%
  left_str := Substr(symbol,1,1)
  right_str := Substr(symbol,2,1)
  sendInput %left_str%%selection%%right_str%
  StringLen, length, selection
  length := length + 1
  sendInput {left %length%}
  return
}

;; 依剪貼簿開頭是否為"http:"來替換$$或一般文字的@@
;; "@@"
send_html(tag, pos1, pos2) {
  selection := GetSelectedText()
  StringLen, length, selection
  if (length = 0) {
    selection := clipboard
  }
  leading := Substr(selection, 1,5)
  ;msgbox %leading%
  newstr = tag
  if (leading = "http:") {
    StringReplace, newstr, tag, $$, %selection%,
	StringLen, length, selection
	length := pos1
  } else {
    StringReplace, newstr, tag, @@, %selection%,
    StringLen, length, selection
	length := length + pos2
  }
  ;msgbox after=%newstr%
  sendInput %newstr%
  sendInput {left %length%}
  return
}

;; 按Ctrl+Comma輸出全形逗點,以此類推
^,::,
^.::。
^;::;
^[:: send_brackets("「」")
^]:: send_brackets("『』")
^![:: send_brackets("【】")
^!]:: send_brackets("《》")
#[:: send_brackets("〔〕")
^':: send_brackets("""""")

;;===== HotString =====
::,a::
  send_html("@@",6,8)
  return

::,img::
  send_html("@@",4,11)
  return

::,aimg::
  send_html("@@",8,8)
  return

腳本下載

##

您可能也會有興趣的類似文章

簡睿

服務於軟體業的資訊老兵。興趣廣泛,學習力佳,樂於分享所知所學。

您可能也會喜歡…

3 個回應

  1. TedKing表示:

    請問我在 WINDOWS 10 設 #G:: 「自訂字串」,但是 WINDOWS 10還是依 WIN+G快捷鍵優先跳出 XBOX GAME BAR, 而不是 AHK 的「自訂字串」,請問大神,這有解嗎? 謝謝

  2. amnesiac表示:

    ^,::,
    这个代码成立吗?无法下载附件,不清楚是否网站的原因。

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *