Skip to content

Instantly share code, notes, and snippets.

@nosami
Created November 16, 2016 14:20
Show Gist options
  • Select an option

  • Save nosami/6d2d2c820b04f1927b1367b00ebe1520 to your computer and use it in GitHub Desktop.

Select an option

Save nosami/6d2d2c820b04f1927b1367b00ebe1520 to your computer and use it in GitHub Desktop.
✔ ~/.karabiner.d/configuration
14:19 $ cat karabiner.json
{
"profiles": [
{
"name": "Default profile",
"selected": true,
"simple_modifications": {
"caps_lock": "left_control"
}
}
]
}
@amirrajan
Copy link

Here is my hammerspoon script:

last_mods = {}

ctrl_table = {
    sends_escape = true,
    last_mods = {}
}

control_shift_timer = hs.timer.delayed.new(0.15, function()
    ctrl_table["send_escape"] = false
    -- log.i("timer fired")
    -- control_key_timer:stop()
end
)

control_handler = function(evt)
  local new_mods = evt:getFlags()
  if last_mods["ctrl"] == new_mods["ctrl"] then
      return false
  end
  if not last_mods["ctrl"] then
    -- log.i("control pressed")
    last_mods = new_mods
    ctrl_table["send_escape"] = true
    -- log.i("starting timer")
    control_key_timer:start()
  else
    -- log.i("contrtol released")
    -- log.i(ctrl_table["send_escape"])
    if ctrl_table["send_escape"] then
      -- log.i("send escape key...")
      hs.eventtap.keyStroke({}, "ESCAPE")
    end
    last_mods = new_mods
    control_key_timer:stop()
  end
  return false
end

control_tap = hs.eventtap.new({12}, control_handler)

control_tap:start()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment