首页 » 前端 » Lua » 正文

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

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

概要

单按 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 代码

{
  "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

-- 打开 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. 联系方式