marketplace/audio

Mouse Media Keys

v0.1.0

@rebindfree

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

Gallery

Mouse Media Keys preview

Readme

Mouse 4 plays and pauses. Mouse 5 skips to the next track. Hold Mouse 5 and scroll to change the volume. It controls whatever is playing, wherever it is.

Needs Rebind 3.5.0 or newer on Windows or Linux. No extra permissions.

Settings

  • Play or pause: default Mouse 4.
  • Next track, or hold and scroll for volume: default Mouse 5. Releasing it without scrolling skips; scrolling while it is held changes the volume instead.
  • Volume steps per notch: 1 to 5 volume key presses per wheel notch.

Key changes apply while the package runs on Rebind 3.9 or newer. On older versions, restart the package.

Limits

  • macOS is not supported yet: Rebind cannot send media keys there.
  • In Rebind's hardware mode with Rebind Link, media keys go through your computer and need Rebind 3.9 or newer.
  • The side buttons no longer go back and forward in browsers while the package runs.
  • Live use remains unverified on Windows and Linux.

Stop

Stop the package from the editor toolbar, or press Left Ctrl + Left Alt + K to stop all scripts.

Reviews

No reviews yet. Be the first, from the app.

Source

Version 0.1.0 (current)

main.luau

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