Hyper Caps Lock

@rebind / hyper-caps-lockv0.1.1Public

Caps Lock acts as Ctrl when held and Escape when tapped.

Files

Older release. Installs get 0.1.1.

main.luau1.0 KB

-- Hyper Caps Lock: hold the source key and it acts as Ctrl; tap it on its own
-- and it sends Escape.

local cfg = UI.Schema({
  source = UI.Keybind("CapsLock", { label = "Key to change" }),
  holdAs = UI.Keybind("LCtrl", { label = "Held, it acts as" }),
  tapAs = UI.Keybind("Escape", { label = "Tapped alone, it sends" }),
  tapMs = UI.Slider(180, {
    min = 100,
    max = 400,
    suffix = " ms",
    label = "A tap is shorter than",
  }),
})

local down, used = false, false

function OnDown(key)
  if key == cfg.source then
    if not down then
      down, used = true, false
      HID.Down(cfg.holdAs)
    end
    return false
  end
  if down then
    used = true
  end
  return true
end

function OnUp(key, durationMs)
  if key ~= cfg.source then
    return true
  end
  if not down then
    return false
  end
  HID.Up(cfg.holdAs)
  if not used and (durationMs or 0) < cfg.tapMs then
    HID.Combo(cfg.tapAs)
  end
  down = false
  return false
end

function OnStop()
  if down then
    HID.Up(cfg.holdAs)
  end
end

3 files, 2.4 KB.