Mouse Media Keys

@rebind / mouse-media-keysv0.1.2Public

Mouse side buttons play, pause and skip; hold one and scroll to change the volume.

Files

Older release. Installs get 0.1.2.

main.luau954 B

-- Mouse Media Keys: one side button plays and pauses, the other skips, and
-- holding it while scrolling changes the volume.

local cfg = UI.Schema({
  play = UI.Keybind("Mouse4", { label = "Play or pause" }),
  next = UI.Keybind(
    "Mouse5",
    { label = "Next track, or hold and scroll for volume" }
  ),
  step = UI.Slider(2, { min = 1, max = 5, label = "Volume steps per notch" }),
})

local holding, scrolled = false, false

Bind(cfg.play, {
  action = function()
    HID.Combo("MediaPlay")
  end,
  release = function() end,
})

Bind(cfg.next, {
  action = function()
    holding, scrolled = true, false
  end,
  release = function()
    holding = false
    if not scrolled then
      HID.Combo("MediaNext")
    end
  end,
})

function OnScroll(delta)
  if not holding then
    return true
  end
  scrolled = true
  local key = if delta > 0 then "VolumeUp" else "VolumeDown"
  for _ = 1, cfg.step do
    HID.Combo(key)
  end
  return false
end

3 files, 2.4 KB.