One-Handed Layout

@rebind / one-handed-layoutv0.1.2Public

Hold Space and the left half of the keyboard types the right half. A tap still types a space.

Files

Older release. Installs get 0.1.2.

main.luau1.7 KB

-- One-Handed Layout: hold the layer key and every left-hand key types its
-- mirror on the right half. A quick tap of the layer key still types it.

local cfg = UI.Schema({
  layer_key = UI.Keybind("Space", { label = "Hold to mirror" }),
  tap_ms = UI.Slider(200, {
    min = 100,
    max = 400,
    suffix = " ms",
    label = "A shorter press still types the key",
  }),
})

local MIRROR = {
  ["1"] = "0",
  ["2"] = "9",
  ["3"] = "8",
  ["4"] = "7",
  ["5"] = "6",
  Q = "P",
  W = "O",
  E = "I",
  R = "U",
  T = "Y",
  A = "Semicolon",
  S = "L",
  D = "K",
  F = "J",
  G = "H",
  Z = "Slash",
  X = "Period",
  C = "Comma",
  V = "M",
  B = "N",
  Tab = "Backspace",
  CapsLock = "Enter",
}

-- macOS reports Caps Lock as a switch, so its mirror is a single tap there
local IS_MAC = _REBIND.platform == "macos"

local layer, used = false, false
local held = {}

function OnDown(key)
  if key == cfg.layer_key then
    if not layer then
      layer, used = true, false
    end
    return false
  end
  local out = layer and MIRROR[key]
  if not out then
    return true
  end
  used = true
  if IS_MAC and key == "CapsLock" then
    HID.Combo(out)
  else
    held[key] = out
    HID.Down(out)
  end
  return false
end

function OnUp(key, durationMs)
  if key == cfg.layer_key then
    if not layer then
      return true
    end
    if not used and (durationMs or 0) < cfg.tap_ms then
      HID.Combo(cfg.layer_key)
    end
    layer, used = false, false
    return false
  end
  local out = held[key]
  if out then
    HID.Up(out)
    held[key] = nil
    return false
  end
  return true
end

function OnStop()
  for _, out in held do
    HID.Up(out)
  end
end

3 files, 3.7 KB.