首页 » 前端 » Lua » 正文

Fn + h/j/k/l/u/d/ to arrows and page scroll,Fn to Esc,CapsLock to Hyper

发布者:站点默认
2019/07/4 浏览数(860) 分类:Lua, 前端 Fn + h/j/k/l/u/d/ to arrows and page scroll,Fn to Esc,CapsLock to Hyper已关闭评论

概要

1
2
3
4
5
6
7
8
9
10
11
12
13
14
单按 Fn 是 Escape
组合时 Fn 还是 Fn
单按 CapsLock 还是 CapsLock,
组合时 CapsLock + g 等于 Ctrl + Option + Command + g
配合 Hammerspoon 可以实现 CapsLock + g 打开指定 App
----
CapsLock -> Hyper
Fn -> Escape
Fn + h -> 左
Fn + j -> 下
Fn + k -> 上
Fn + l -> 右
Fn + u -> page up
Fn + d -> page down

用法

把 fn-capslock-enhancement.json 放到 ~/.config/karabiner/assets/complex_modifications/ 。

fn-capslock-enhancement.json 代码

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
{
  "title": "Fn/CapsLock Enhancement",
  "rules": [
    {
      "description": "Held CapsLock to Hyper",
      "manipulators": [
        {
          "from": {
            "key_code": "caps_lock",
            "modifiers": {
              "optional": ["any"]
            }
          },
          "to": [
            {
              "key_code": "right_control",
              "modifiers": ["right_command", "right_option", "right_shift"]
            }
          ],
          "to_if_alone": {
            "hold_down_milliseconds": 100,
            "key_code": "caps_lock"
          },
          "type": "basic"
        }
      ]
    },
    {
      "description": "Alone Fn to Escape",
      "manipulators": [
        {
          "type": "basic",
          "from": {
            "key_code": "fn",
            "modifiers": {
              "optional": ["any"]
            }
          },
          "to": [
            {
              "key_code": "fn",
              "lazy": true
            }
          ],
          "to_if_alone": [
            {
              "key_code": "escape"
            }
          ]
        }
      ]
    },
    {
      "description": "Fn + h/j/k/l to arrows",
      "manipulators": [
        {
          "type": "basic",
          "from": {
            "key_code": "h",
            "modifiers": {
              "mandatory": ["fn"],
              "optional": ["any"]
            }
          },
          "to": [
            {
              "key_code": "left_arrow"
            }
          ]
        },
        {
          "type": "basic",
          "from": {
            "key_code": "j",
            "modifiers": {
              "mandatory": ["fn"],
              "optional": ["any"]
            }
          },
          "to": [
            {
              "key_code": "down_arrow"
            }
          ]
        },
        {
          "type": "basic",
          "from": {
            "key_code": "k",
            "modifiers": {
              "mandatory": ["fn"],
              "optional": ["any"]
            }
          },
          "to": [
            {
              "key_code": "up_arrow"
            }
          ]
        },
        {
          "type": "basic",
          "from": {
            "key_code": "l",
            "modifiers": {
              "mandatory": ["fn"],
              "optional": ["any"]
            }
          },
          "to": [
            {
              "key_code": "right_arrow"
            }
          ]
        }
      ]
    },
    {
      "description": "Fn + u/d to page scroll",
      "manipulators": [
        {
          "type": "basic",
          "from": {
            "key_code": "u",
            "modifiers": {
              "mandatory": ["fn"],
              "optional": ["any"]
            }
          },
          "to": [
            {
              "key_code": "page_up"
            }
          ]
        },
        {
          "type": "basic",
          "from": {
            "key_code": "d",
            "modifiers": {
              "mandatory": ["fn"],
              "optional": ["any"]
            }
          },
          "to": [
            {
              "key_code": "page_down"
            }
          ]
        }
      ]
    }
  ]
}

到 Karabiner-Elements 中启用这些规则

规则在 complex_modifications 标签页中。

~/.hammerspoon/init.lua

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
-- 打开 Finder
hs.hotkey.bind(
  {'cmd'},
  'e',
  function()
    hs.execute('open ~')
  end
)
 
-- 打开常用工具
apps = {
  {key = 'A', app = '/Applications/Affinity Photo.app'},
  {key = 'C', app = '/Applications/Utilities/Digital Color Meter.app'},
  {key = 'D', app = '/Applications/TablePlus.app'},
  {key = 'F', app = '/Applications/Fork.app'},
  {key = 'G', app = '/Applications/Google Chrome.app'},
  {key = 'M', app = '/Applications/Utilities/Activity Monitor.app'},
  {key = 'Q', app = '/Applications/QQ.app'},
  {key = 'S', app = '/Applications/Seafile Client.app'},
  {key = 'T', app = '/Applications/Utilities/Terminal.app'},
  {key = 'V', app = '/Applications/Visual Studio Code.app'},
  {key = 'X', app = '/Applications/Xcode.app'}
}
hs.fnutils.each(
  apps,
  function(entry)
    hs.hotkey.bind(
      {'ctrl', 'alt', 'cmd'},
      entry.key,
      nil,
      function()
        hs.application.launchOrFocus(entry.app)
      end
    )
  end
)

— 完 —

点击返回顶部
  1. 留言
  2. 联系方式
Loading...