一、安装 AutoHotkey
官方安装链接:https://autohotkey.com/download/ahk-install.exe
- 【home】Tab页:选择【Custom lnstallation】自定义安装;
- 【version】Tab页:选择版本,与操作系统一致即可(我选择
Unicode 64-bit
); - 【location】Tab页:选择软件安装位置
- 点击【next】继续安装;
- 点击【install】软件就会安装;
- AutoHotkey安装完成,点击
exit
退出软件安装,点击其他
可以打开软件帮助界面。
二、配置
在桌面新建一个 MyHotkeyScript.ahk文件,一记事本方式打开并复制以下代码:
; 分号以及分号后的内容代表注释,以下为代码解释
#IfWinActive ahk_exe Typora.exe
{
; alt+0 黑色
!0::addFontColor("black")
; alt+1 红色
!1::addFontColor("red")
; alt+2 橙色
!2::addFontColor("orange")
; alt+3 黄色
!3::addFontColor("yellow")
; alt+4 绿色
!4::addFontColor("green")
; alt+5 青色
!5::addFontColor("cyan")
; alt+6 浅蓝色
!6::addFontColor("cornflowerblue")
; alt+7 紫色
!7::addFontColor("purple")
}
; 快捷增加字体颜色
addFontColor(color){
clipboard := "" ; 清空剪切板
Send {ctrl down}c{ctrl up} ; 复制
; SendInput {Text} ; 解决中文输入法问题
SendInput {TEXT}<font color='%color%'>
SendInput {ctrl down}v{ctrl up} ; 粘贴
If(clipboard = ""){
SendInput {TEXT}</font> ; Typora 在这不会自动补充
}else{
SendInput {TEXT}</ ; Typora中自动补全标签
}
}
三、运行
- 双击文件运行【用AutoHotkey运行】,打开AutoHotkey程序看见以下内容;
Script lines most recently executed (oldest first). Press [F5] to refresh. The seconds elapsed between a line and the one after it is in parentheses to the right (if not 0). The bottommost line's elapsed time is the number of seconds since it executed.
---- C:\Users\liang\Desktop\MyHotkeyScript.ahk
003: {
005: Return (58.16)
Press [F5] to refresh.
- 重启Typora,测试快捷键是否有效,Alt + 01234567 分别是各种颜色。