├── .gitignore ├── README.md └── myhotkey.ahk /.gitignore: -------------------------------------------------------------------------------- 1 | .history -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # myHotKey 2 | 3 | > 我只想看看还有多少人用 window 系统办公,像我一样在太阳下低头。 4 | 5 | 工欲善其事,必先利其器。买 mac 和 [HHKB](https://xiaozhou.net/got_hhkb_pro_2-2013-06-03.html),但作为一名收入还不是很稳定的前端,公司又不标配这些,又不想用自己的 mac 办公。工作难免会用 window 系统 ,那就学点 `autohotkey` , 效率贼 6。毕竟现在文档已经很成熟了,想搞事情还是可以的。什么 mac 键,抛弃 ctrl,工作流,都依你,开心就好! 6 | 7 | * [官网](https://www.autohotkey.com/) 8 | * [下载](https://www.autohotkey.com/download/) 9 | * [中文](https://wyagd001.github.io/zh-cn/docs/AutoHotkey.htm) 10 | 11 | 可以参考下,[我的配置](https://github.com/leer0911/myHotKey)。先来看下我都用`autohotkey` 做了什么。虽然可以用很多工具实现,但我还是会选择不安装过多软件,能自己实现不是很好么~ window 下我只推荐[listary](http://www.listary.com/)。 12 | 13 | 用的舒服的话,可以把 `myHotKey.ahk` 文件放在开机自动启动即可。 14 | 15 | ## myHotKey 能做什么 16 | 17 | 下面是我整合的一些常用操作: [github 地址](https://github.com/leer0911/myHotKey) PS: 当然不一定是你想要的。而且很可能不习惯,所以在用之前你可以先大概看一下,最后修改为你自己想要的 ahk 脚本。 18 | 19 | * 快速打开常用网址,如按下 f4 即可打开我的 github 20 | 21 | ```ahk 22 | f4::Run http://github.com/leer0911/ 23 | ``` 24 | 25 | * 搜索引擎整合,如按下 f1 可以用谷歌搜索选中的文本,f6 可以触发搜索 前端常用的[devdocs](http://devdocs.io/) 如 mac 里面的`dash` 26 | 27 | ```ahk 28 | f1:: 29 | current_clipboard = %Clipboard% 30 | Send ^c 31 | ClipWait, 1 32 | Run http://www.google.com/search?q=%Clipboard% 33 | Clipboard = %current_clipboard% 34 | return 35 | ``` 36 | 37 | * 光标快速移动,映射了键盘上的方向键。(把 alt 键当 mac 键用) 但是如果是用 vscode 编辑器。我还是觉得 `jumpy` 插件最好跳转了。用的不开心还能改源码~ 38 | 39 | * alt+i 触发 向上键 40 | * alt+j 触发 向左键 41 | * alt+k 触发 向下键 42 | * alt+l 触发 向右键 43 | 44 | ```ahk 45 | ; 键盘键位替换,如 上下左右 删除 全选 46 | + ^ - = ! {} () . , 79 | >+h::send < 80 | >+s::send $ 81 | >+j::send {#} 82 | >+x::send * 83 | >+u::send > 84 | >+o::send {^} 85 | >+i::send {+} 86 | >+n::send - 87 | >+m::send {=} 88 | >+l::send {{} 89 | >+k::send ( 90 | >+g::send {!} 91 | >+d::send . 92 | >+f::send {,} 93 | >+space::send {=} 94 | ``` 95 | 96 | * 我最常用的功能应该是 任意软件 置顶 , 改变软件透明度。对于我们前端来说。总觉得屏幕不够用,老板又不肯买两个屏幕。怎么办。编辑器半透明呗,这样就可以边敲代码边看设计稿了。看 API 的时候也是。可以让编辑器置顶,半透明再配合 浏览器的 `vimium` 插件,你就可以边敲代码边看文档了。 97 | 98 | * 双击 shift 实现软件置顶 99 | * alt + + 实现降低软件透明度 100 | * alt + - 实现增加软件透明度 101 | 102 | * 更多的功能,待你们去挖掘。记得分享~ 103 | 104 | **觉得可以的话,可以继续看下教程。** 105 | 106 | ## 快速入门 107 | 108 | 毕竟学习一门新语言是需要时间的,下面只是简单描述下我用 autohotkey 接触到的东西,这样当你想用我这套 hotkey 的时候能看懂并能修改成自己想要的。当然,想系统学习的同学可以直接参考[官方文档](https://wyagd001.github.io/zh-cn/docs/Tutorial.htm) 109 | 110 | * 下载&安装 autohotkey 111 | * 新建 后缀为.ahk 的文件并运行 112 | 113 | ### 热键 114 | 115 | 首先了解,代码中修饰符都代表了键盘中的哪些按键,你只要知道了修饰符边可以通过代码来让按键搞事情(脚本动作)。热键是通过一对 :: 创建的. 按键名或组合按键名必须在 :: 左边. 代码则跟在后面, 以 Return 结束。(单行可省略 return) 比如 116 | 117 | ```ahk 118 | ^j:: 119 | Send, My First Script 120 | Return 121 | ``` 122 | 123 | 当你的 autohotkey 正常运行你编写的代码时。按下 `ctrl+j` 会输出 `My First Script` 这么一段文字。 124 | 125 | | 符号 | 说明 | 126 | | ---- | -------------- | 127 | | # | win | 128 | | ! | alt | 129 | | ^ | control | 130 | | + | shift | 131 | | & | 用于组合按键 | 132 | | < | 左按键 | 133 | | > | 右按键 | 134 | | \* | 通配符 | 135 | | ~ | 保留按键原功能 | 136 | | UP | 释放时触发热键 | 137 | 138 | [详细](https://wyagd001.github.io/zh-cn/docs/Hotkeys.htm) 139 | 140 | #### 禁用按键 141 | 142 | 通过不为按键或按键组合的热键指定任何操作可以在整个系统中完全禁用它们. 下面的例子中禁用了右 Windows 键: 143 | 144 | ```ahk 145 | RWin::return 146 | ``` 147 | 148 | #### 上文相关按键 149 | 150 | 当需要在某些特定软件中设定热键则需要了解,上下文按键 151 | 152 | [#IfWinActive/Exist](https://wyagd001.github.io/zh-cn/docs/commands/_IfWinActive.htm) 和 [#if](https://wyagd001.github.io/zh-cn/docs/commands/_If.htm)指令可以用来让热键根据不同的条件执行不同的动作例如: 153 | 154 | ```ahk 155 | #IfWinActive, ahk_class Notepad 156 | ^a::MsgBox 你在记事本中按下了 Ctrl-A . 而在其他窗口中按下 Ctrl-A 将原样发送. 157 | #c::MsgBox 你在记事本中按下了 Win-C 组合键. 158 | 159 | #IfWinActive 160 | #c::MsgBox 你在非记事本程序中按下了 Win-C . 161 | 162 | #If MouseIsOver("ahk_class Shell_TrayWnd") 163 | WheelUp::Send {Volume_Up} ; 在任务栏上滚动滚轮:增加/减小音量. 164 | WheelDown::Send {Volume_Down} ; 165 | ``` 166 | 167 | ### 热字符串 168 | 169 | 热字串主要用于扩展你的缩写库(自动替换). 当然, 它也可以用来映射任何脚本动作。比如 170 | 171 | ```ahk 172 | ::ftw::Free the whales 173 | ``` 174 | 175 | 热字串会将你输入的"ftw"转换为"Free the whales"。 176 | 177 | ## 搞事情啦 178 | 179 | 知道了热键和热字符串,肯定想知道能用他来搞什么事情。 180 | 181 | ### 发送按键 182 | 183 | 现在你决定发送一些按键到一个程序中. 你可以使用 Send 命令. Send 表示发送按键, 模拟打字或按键操作.如 184 | 185 | ```ahk 186 | Send !+a 187 | ``` 188 | 189 | 会按下 ALT+SHIFT+a 190 | 191 | [更多 send 命令](https://wyagd001.github.io/zh-cn/docs/commands/Send.htm) 192 | 193 | ### 运行程序和网页 194 | 195 | 想要运行画图(mspaint.exe), 计算器(calc.exe), 脚本`.ahk` 等程序或要打开一个文件夹, 你可以使用 Run 命令. 你还可以用这个命令打开一个网址, 比如打开 `https://autohotkey.com/` . 如果你想打开一个已经安装好的程序, 也很简单, 就像这样: 196 | 197 | ```ahk 198 | ; 运行一个程序. 注: 大部分的程序可能需要完整路径. 199 | Run, %A_ProgramFiles%\Some_Program\Program.exe 200 | 201 | ; 打开一个网址 202 | Run, https://autohotkey.com 203 | ``` 204 | 205 | [更多 run 命令](https://wyagd001.github.io/zh-cn/docs/commands/Run.htm) 206 | 207 | ### 命令和函数索引 208 | 209 | AutoHotkey 有两个重要的工具供开发者使用:命令和函数 210 | 211 | [官方文档](https://wyagd001.github.io/zh-cn/docs/commands/index.htm) 212 | -------------------------------------------------------------------------------- /myhotkey.ahk: -------------------------------------------------------------------------------- 1 | ; 常用网址 ---------------------------------------------- 2 | 3 | f4::Run http://github.com/leer0911/ 4 | 5 | 6 | ; 搜索相关 ---------------------------------------------- 7 | 8 | ; 用谷歌搜索选中文本 9 | f1:: 10 | current_clipboard = %Clipboard% 11 | Send ^c 12 | ClipWait, 1 13 | Run http://www.google.com/search?q=%Clipboard% 14 | Clipboard = %current_clipboard% 15 | return 16 | 17 | ; 用百度搜索选中文本 18 | f7:: 19 | current_clipboard = %Clipboard% 20 | Clipboard = 21 | Send ^c 22 | ClipWait, 1 23 | Run https://www.baidu.com/s?wd=%Clipboard% 24 | Clipboard = %current_clipboard% 25 | return 26 | 27 | ; devdocs搜索 28 | f6:: 29 | Send ^c 30 | Run http://devdocs.io/ 31 | sleep 1000 32 | Send ^v 33 | Send {enter} 34 | return 35 | 36 | ; 用MDN搜索选中文本 37 | f3:: 38 | current_clipboard = %Clipboard% ; 39 | Clipboard = ; 40 | Send ^c 41 | ClipWait, 1 ; 42 | Run https://developer.mozilla.org/zh-CN/search?q=%Clipboard% 43 | Clipboard = %current_clipboard% ; 44 | return 45 | 46 | ; 有道翻译 ps 必须将有道翻译设置为对应快捷键 47 | !y:: 48 | Send ^d 49 | Send ^c 50 | return 51 | 52 | ; vscode 函数跳转 53 | !t:: 54 | Send ^d 55 | Send ^c 56 | sleep 100 57 | Send !^r 58 | sleep 200 59 | Send ^v 60 | return 61 | 62 | ; 热字符串 ----------------------------------------------- 63 | 64 | :*:gitc::git clone +{Insert} 65 | ; bash命令 66 | :*:cdd::cd ~/Desktop 67 | :*:ddd::~/Desktop/ 68 | :*:ccc::~/Desktop/d 69 | :*:gitpp::git push --no-verify 70 | :*:qqq::qshell.exe qupload ~/Desktop/qupload/ 71 | :*:cpp::cp ~/Desktop ~/Desktop 72 | :*:rmm::rm -rf 73 | 74 | ; 更改大小写键位为 alt + Capslock , Capslock 修改为 Rshift 75 | !Capslock::Capslock 76 | Capslock::Rshift 77 | Rshift::ctrl 78 | 79 | ; 常用符号快捷键生成 如 < $ # * > + ^ - = ! {} () . , 80 | >+h::send < 81 | >+s::send $ 82 | >+j::send {#} 83 | >+x::send * 84 | >+u::send > 85 | >+o::send {^} 86 | >+i::send {+} 87 | >+n::send - 88 | >+m::send {=} 89 | >+l::send {{} 90 | >+k::send ( 91 | >+g::send {!} 92 | >+d::send . 93 | >+f::send {,} 94 | >+space::send {=} 95 | 96 | ; 鼠标事件 ----------------------------------------------- 97 | 98 | #z::LButton 99 | #h::LButton 100 | #w::send {WheelUp} 101 | #s::send {WheelDown} 102 | 103 | ; 快捷键修改 --------------------------------------------- 104 | 105 | ; 键盘键位替换,如 上下左右 删除 全选 106 | Shift:: 156 | if (A_PriorHotKey = ">Shift" AND A_TimeSincePriorHotKey < 500) 157 | { 158 | WinGet ow, id, A 159 | WinTopToggle(ow) 160 | } 161 | return 162 | #0:: 163 | !0:: 164 | WinGet ow, id, A 165 | WinTopToggle(ow) 166 | return 167 | WinTopToggle(w) { 168 | 169 | WinGetTitle, oTitle, ahk_id %w% 170 | Winset, AlwaysOnTop, Toggle, ahk_id %w% 171 | WinGet, ExStyle, ExStyle, ahk_id %w% 172 | if (ExStyle & 0x8) ; 0x8 为 WS_EX_TOPMOST.在WinGet的帮助中 173 | oTop = Ture 174 | else 175 | oTop = False 176 | tooltip %oTitle% %oTop% 177 | SetTimer, RemoveToolTip,1000 178 | return 179 | 180 | RemoveToolTip: 181 | SetTimer, RemoveToolTip, Off 182 | ToolTip 183 | return 184 | } 185 | 186 | #=:: 187 | !=:: ;; alt-= 188 | WinGet, ow, id, A 189 | WinTransplus(ow) 190 | return 191 | #-:: 192 | !-:: ;; alt-- 193 | WinGet, ow, id, A 194 | WinTransMinus(ow) 195 | return 196 | ;; WinTransplus WinTransMinus 对ahk_id为w的窗口 197 | ;; 进行透明度增减,每次幅度为10 198 | WinTransplus(w){ 199 | 200 | WinGet, transparent, Transparent, ahk_id %w% 201 | if transparent < 255 202 | transparent := transparent+10 203 | else 204 | transparent = 205 | if transparent 206 | WinSet, Transparent, %transparent%, ahk_id %w% 207 | else 208 | WinSet, Transparent, off, ahk_id %w% 209 | return 210 | } 211 | WinTransMinus(w){ 212 | 213 | WinGet, transparent, Transparent, ahk_id %w% 214 | if transparent 215 | transparent := transparent-10 216 | else 217 | transparent := 240 218 | WinSet, Transparent, %transparent%, ahk_id %w% 219 | return 220 | } 221 | --------------------------------------------------------------------------------