微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Autohotkey-如何存储和使用unicode?

如何解决Autohotkey-如何存储和使用unicode?

下面是我的代码。 AHK文件通过BOM保存为UTF-8,只要将它粘贴到脚本中,我就可以看到Unicode字符。但是每次我保存脚本并重新打开它时,unicode字符都会变成问号和乱码。运行“ sendinput”时,输出也会显示为问号和乱码,而不是实际的unicode表情符号。

MyVarEmoticon =
      (Ltrim
         What is your choice? (Enter #):

         1. (╯°□°)╯︵ ┻━┻
         
         2. (┛ಠ_ಠ)┛彡┻━┻
         
         3. (╯°Д°)╯︵/(.□ . \)

         4. ┏━┓┏━┓┏━┓ ︵ /(^.^/)

      )


InputBox,MyVarEmoticonChoices,Emoticon Choices,%MyVarEmoticon%,400,% HEmoticon(MyVarEmoticon),1
          
HEmoticon(MyVarEmoticon)
    {
     StringReplace,MyVarEmoticon,myvaremoticon,`n,UseErrorLevel
     Lines:=ErrorLevel+1
     height:=lines * 30 ; play with this value !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
     ;MsgBox % height
     If (Height < 40) ; too low 
        Height+=80
     Return height
    }   

if ErrorLevel {
        ;MsgBox,CANCEL was pressed.
    
} else {    

    
    if (MyVarEmoticonChoices = "1"){
        MyVarEmoticonChoices = (╯°□°)╯︵ ┻━┻
    }
    if (MyVarEmoticonChoices = "2"){
        MyVarEmoticonChoices = (┛ಠ_ಠ)┛彡┻━┻
    }
    if (MyVarEmoticonChoices = "3"){
        MyVarEmoticonChoices = (╯°Д°)╯︵/(.□ . \)
    }
    if (MyVarEmoticonChoices = "4"){
        MyVarEmoticonChoices = ┏━┓┏━┓┏━┓ ︵ /(^.^/)
    }

        WinGetPos,X,Y,Width,Height,ahk_exe ToW.exe,XVar = %X%
        YVar = %Y%
        WVar = %Width%
        HVar = %Height%
        XWVar = % XVar+39
        YHVar = % YVar+682
                                    
        Sleep,200
        sendinput,{raw}%MyVarEmoticonChoices%

解决方法

尽管此代码中有些奇怪的东西,但是如果使用正确的编码保存,它似乎可以按预期工作。
我真的不知道当您尝试保存它时出了什么问题,也许尝试解释要在使用的编辑器中保存它的步骤。

如果您不想担心文件编码,则可以将字符存储为代码点。例如
您可以在Google搜索中找到一个快速的小转换器,这是我在Google搜索中找到的一个转换器:
http://unicode.scarfboy.com/?s=%28%E2%95%AF%C2%B0%E2%96%A1%C2%B0%29%E2%95%AF%EF%B8%B5+%E2%94%BB%E2%94%81%E2%94%BB
然后您可以使用Chr()将代码点转换为字符。

例如:

emote := "0028 256F 00B0 25A1 00B0 0029 256F FE35 0020 253B 2501 253B"
for each,codepoint in StrSplit(emote," ")
   output .= Chr("0x" codepoint)

Clipboard := output
SendInput,^v

在这里,我还利用剪贴板并发送 Ctrl + v ,如果可以使用的话,这是一个很好的技巧。特别是对于长文本,我想这不是真的,但我认为我会显示出来。

或者,如果您想Send字符串,则可以使用Unicode notation

emote := "0028 256F 00B0 25A1 00B0 0029 256F FE35 0020 253B 2501 253B"
for each," ")
   output .= "{U+" codepoint "}"

SendInput,% output
;SendInput,% "{U+0028}{U+256F}{U+00B0}{U+25A1}{U+00B0}{U+0029}{U+256F}{U+FE35}{U+0020}{U+253B}{U+2501}{U+253B}"

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。