Autohotkey自定义快捷键修改中英文标点符号

有时候我们写中文的时候会用到英文的标点符号,比如english(en),这里我用的autohotkey命令实现的,ALT+J将前一个符号切换中英文状态,ALT+L将光标后面的符号切换中英文状态。
核心代码如下,构建一个字典即可,然后控制光标前后的内容选中并复制到剪切板,查询字典并替换。这个字典来源于一个github库,我借助这个库进行了魔改。
charReplaceDict :={"?":"?","?":"?",">":"》","》":">","\":"、","、":"\",",":",",",":",",".":"。","。":".","<":"《","《":"<","[":"【","【":"[","]":"】","】":"]",";":";",";":";",":":":",":":":","^":"……","……":"^","!":"!","!":"!","`":"·","·":"`","$":"¥","¥":"$","(":"(","(":"(",")":")",")":")","_":"——","——":"_","/":"、","'":"‘’","''":"‘’","‘’":"''","‘":"'","’":"'","""":"“”","""""":"“”","“”":"""""","“":"""","”":""""}

!j::    ;光标前面的,再写一个光标后面的就好了
    ClipSaved := ClipboardAll
    Send, +{Left}
    sleep, 200
    Send, ^c
    sleep, 200
    clipboard = % charReplaceDict.HasKey(clipboard)? charReplaceDict[clipboard]:clipboard
    Send, ^v
    sleep, 200
    clipboard := ClipSaved
    sleep, 200
    ClipSaved = ;
return

!l::    ;光标前面的,再写一个光标后面的就好了
    ClipSaved := ClipboardAll
    Send, +{Right}
    sleep, 200
    Send, ^c
    sleep, 200
    clipboard = % charReplaceDict.HasKey(clipboard)? charReplaceDict[clipboard]:clipboard
    Send, ^v
    sleep, 200
    clipboard := ClipSaved
    sleep, 200
    ClipSaved = ;
return

给TA捐赠
共{{data.count}}人
人已捐赠
其他

runany翻译插件分享

2022-10-8 14:17:40

其他

Autohotkey调用百度翻译API完整版

2022-10-10 9:10:58

3 条回复 A文章作者 M管理员
  1. ahk小明

    非常有用?

    • VVXahk

      针对使用过程中的缺点,做了优化,感谢认可?

  2. VVXahk

    在使用过程中发现了有两个不足,首先是光标后面的字符修改后,应该把光标回调,请自行修改;其次是对于中文的下划线“——”没有特别好的修改方法,我的做法是,在字典中添加”—”:”_”项用来辅助找到中文破折号,然后在代码!j部分,正常执行完以后添加判断 charReplaceDict :={“?”:”?”,”?”:”?”,”>”:”》”,”》”:”>”,””:”、”,”、”:””,”,”:”,”,”,”:”,”,”.”:”。”,”。”:”.”,”<":"《","《":"<","[":"【","【":"[","]":"】","】":"]",";":";",";":";",":":":",":":":","^":"……","……":"^","!":"!","!":"!","`":"·","·":"`","$":"¥","¥":"$","(":"(","(":"(",")":")",")":")","_":"——","——":"_","—":"_","/":"、","'":"‘’","''":"‘’","‘’":"''","‘":"'","’":"'","""":"“”","""""":"“”","“”":"""""","“":"""","”":""""} !j:: ;光标前面的,再写一个光标后面的就好了 ClipSaved := ClipboardAll Send, +{Left} sleep, 200 Send, ^c sleep, 200 clipboard = % charReplaceDict.HasKey(clipboard)? charReplaceDict[clipboard]:clipboard Send, ^v sleep, 100 spstr:=clipboard ndl:="_" ;对于特殊的情况就是这个下划线,首先字典做了更改,然后在这里进行一下判断 If InStr(spstr,ndl) {;这里加上这么多延迟是因为我用vscode中的markdown写东西键盘输入延迟比较高,可以根据实际情况自己调整时间 Send, {Left} sleep, 100 Send, {Backspace} sleep, 100 Send, {Right} } clipboard := ClipSaved sleep, 100 ClipSaved = ; return

个人中心
购物车
优惠劵
有新私信 私信列表
搜索