Gist & Cookbook ...

小目标:每天能够提交一行代码 ...

使用AutoHotkey将Windows的键位改成和MacOS一致

吴亮's Avatar 2019-07-09

  1. 1. 默认Windows键位的修改
  2. 2. HHKB键盘配置

习惯了MacOS,觉得Command键真心方便,但公司发的是Windows,键位真心不适应。于是就想着把Windows的键位改成和MacOS一致,尝试了几款工具,觉得没有一款能像Karabiner-Elements那样方便的。直到最后发现了AutoHotkey,觉得还是不错的,有必要记录一下。

默认Windows键位的修改

我一般只用左手边的功能键,因此我只改了左手边的几个键位

主要思想就是:

  • Alt 改成 Ctrl
  • Win 改成 Alt
  • Ctrl 改成 Shift
  • 如果单独按了Win键,禁用
  • 另外,针对一些特殊的软件,比如XShell、Putty等,做了特殊的判断

源码地址

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
; LAlt::RCtrl
; LWin::RAlt
; LShift::RCtrl
; LCtrl::RShift
; 类似windows的win+d
; !d::send #d

; 重写,想法参考:http://blog.csdn.net/william_lv/article/details/53320072
; ! Alt
; ^ Control
; + Shift
; # Win

LAlt & 0::send,^0
LAlt & 1::
SetTitleMatchMode 2
If WinActive("PuTTY") {
send,!1
}
else {
send,^1
}
return
LAlt & 2::
SetTitleMatchMode 2
If WinActive("PuTTY") {
send,!2
}
else {
send,^2
}
return
LAlt & 3::
SetTitleMatchMode 2
If WinActive("PuTTY") {
send,!3
}
else {
send,^3
}
return
LAlt & 4::
SetTitleMatchMode 2
If WinActive("PuTTY") {
send,!4
}
else {
send,^4
}
return
LAlt & 5::
SetTitleMatchMode 2
If WinActive("PuTTY") {
send,!5
}
else {
send,^5
}
return
LAlt & 6::
SetTitleMatchMode 2
If WinActive("PuTTY") {
send,!6
}
else {
send,^6
}
return
LAlt & 7::
SetTitleMatchMode 2
If WinActive("PuTTY") {
send,!7
}
else {
send,^7
}
return
LAlt & 8::
SetTitleMatchMode 2
If WinActive("PuTTY") {
send,!8
}
else {
send,^8
}
return
LAlt & 9::
SetTitleMatchMode 2
If WinActive("PuTTY") {
send,!9
}
else {
send,^9
}
return
LAlt & a::send,^a
LAlt & b::send,^b
; 参考: https://github.com/mahengyang/code/blob/master/puffin/AutoHotkey.ahk
LAlt & c::
SetTitleMatchMode 2
If WinActive("Xshell") {
send,^+c
}
else {
If WinActive("PuTTY") {
send, ^{Insert}
}
else {
If WinActive("FinalShell") {
send,^+b
}
else {
send,^c
}
}
}
return
LAlt & d::send,^d
LAlt & e::send,^e
LAlt & f::send,^f
LAlt & g::send,^g
LAlt & h::send,^h
LAlt & i::send,^i
LAlt & j::send,^j
LAlt & k::send,^k
LAlt & l::send,^l
LAlt & m::send,^m
LAlt & n::send,^n
LAlt & o::send,^o
LAlt & p::send,^p
LAlt & q::send,^q
LAlt & r::send,^r
LAlt & s::send,^s
LAlt & t::send,^t
LAlt & u::send,^u
LAlt & v::
SetTitleMatchMode 2
If WinActive("Xshell") {
send,^+v
}
else {
If WinActive("PuTTY") {
send, +{Insert}
}
else {
If WinActive("FinalShell") {
send,^+v
}
else {
send,^v
}
}
}
return
LAlt & w::send,^w
LAlt & x::send,^x
LAlt & y::send,^y
LAlt & z::send,^z
LAlt & /::send,^/
LAlt & Up::send, ^{Up}
LAlt & Down::send, ^{Down}
LAlt:: return

; 禁用单独的windows建
LWin::return

HHKB键盘配置

我还有一块HHKB,像让它也在Windows上快乐地玩转起来

源码地址

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
; LAlt::RCtrl
; LWin::RAlt
; LShift::RCtrl
; LCtrl::RShift
; 类似windows的win+d
; !d::send #d

; 重写,想法参考:http://blog.csdn.net/william_lv/article/details/53320072
; ! Alt
; ^ Control
; + Shift
; # Win

LWin & 0::send,^0
LWin & 1::
SetTitleMatchMode 2
If WinActive("PuTTY") {
send,!1
}
else {
send,^1
}
return

LWin & 2::
SetTitleMatchMode 2
If WinActive("PuTTY") {
send,!2
}
else {
send,^2
}
return
LWin & 3::
SetTitleMatchMode 2
If WinActive("PuTTY") {
send,!3
}
else {
send,^3
}
return
LWin & 4::
SetTitleMatchMode 2
If WinActive("PuTTY") {
send,!4
}
else {
send,^4
}
return
LWin & 5::
SetTitleMatchMode 2
If WinActive("PuTTY") {
send,!5
}
else {
send,^5
}
return
LWin & 6::
SetTitleMatchMode 2
If WinActive("PuTTY") {
send,!6
}
else {
send,^6
}
return
LWin & 7::SetTitleMatchMode 2
If WinActive("PuTTY") {
send,!7
}
else {
send,^7
}
return
LWin & 8::
SetTitleMatchMode 2
If WinActive("PuTTY") {
send,!8
}
else {
send,^8
}
return
LWin & 9::
SetTitleMatchMode 2
If WinActive("PuTTY") {
send,!9
}
else {
send,^9
}
return
LWin & a::send,^a
LWin & b::send,^b
; 参考: https://github.com/mahengyang/code/blob/master/puffin/AutoHotkey.ahk
LWin & c::
SetTitleMatchMode 2
If WinActive("Xshell") {
send,^+c
}
else {
If WinActive("PuTTY") {
send, ^{Insert}
}
else {
send,^c
}
}
return
LWin & d::send,^d
LWin & e::send,^e
LWin & f::send,^f
LWin & g::send,^g
LWin & h::send,^h
LWin & i::send,^i
LWin & j::send,^j
LWin & k::send,^k
LWin & l::send,^l
LWin & m::send,^m
LWin & n::send,^n
LWin & o::send,^o
LWin & p::send,^p
LWin & q::send,^q
LWin & r::send,^r
LWin & s::send,^s
LWin & t::send,^t
LWin & u::send,^u
LWin & v::
SetTitleMatchMode 2
If WinActive("Xshell") {
send,^+v
}
else {
If WinActive("PuTTY") {
send, +{Insert}
}
else {
send,^v
}
}
return
LWin & w::send,^w
LWin & x::send,^x
LWin & y::send,^y
LWin & z::send,^z
LWin & /::send,^/
; https://stackoverflow.com/questions/9696516/how-to-remap-altj-as-alttab-using-autohotkey?rq=1
LWin & Tab::AltTab
LWin & Space::send, !{space}
; LWin & mouseLeftButton
LWin & LButton::send, ^{LButton}
LWin & Up::send, ^{Up}
LWin & Down::send, ^{Down}
; 禁用单独的windows建
LWin::return

LShift::RCtrl
LCtrl::RShift

LAlt & a::send,#a
LAlt & b::send,#b
LAlt & c::send,#c
LAlt & d::send,#d
LAlt & e::send,#e
LAlt & f::send,#f
LAlt & g::send,#g
LAlt & h::send,#h
LAlt & i::send,#i
LAlt & j::send,#j
LAlt & k::send,#k
LAlt & l::send,#l
LAlt & m::send,#m
LAlt & n::send,#n
LAlt & o::send,#o
LAlt & p::send,#p
LAlt & q::send,#q
LAlt & r::send,#r
LAlt & s::send,#s
LAlt & t::send,#t
LAlt & u::send,#u
LAlt & v::send,#v
LAlt & w::send,#w
LAlt & x::send,#x
LAlt & y::send,#y
LAlt & z::send,#z

; HHKB 左上角三个键修改
`::Backspace
\::`
|::~
Backspace::\
RShift & Backspace::|
RShift & Escape::~

本文作者 : 吴亮
本文使用 署名-非商业性使用-相同方式共享 4.0 国际 (CC BY-NC-SA 4.0) 协议
本文链接 : https://www.wuliang.me/configure-windows-keyboard-map-like-mac-by-autohotkey/

本文最后更新于 天前,文中所描述的信息可能已发生改变