Push to Talk, Unclipped

@rebind / push-to-talk-unclippedv0.1.2Public

Put push to talk on a mouse button and keep the mic open a moment after release, so your last word gets through.

Files

main.luau996 B

-- Push to Talk, Unclipped: hold the talk button to hold a key Discord can
-- bind, and keep it held for a short tail after you let go.

local KEYS = { "F13", "F14", "F15", "F16", "F17", "F18", "F19", "F20" }

local cfg = UI.Schema({
  talk = UI.Keybind("Mouse4", { label = "Hold to talk" }),
  output = UI.Select("F13", KEYS, { label = "Key Discord listens for" }),
  tail = UI.Slider(250, {
    min = 0,
    max = 800,
    suffix = " ms",
    label = "Hold after release",
  }),
})

local held = nil
local pending = nil

local function release()
  if held then
    HID.Up(held)
    held = nil
  end
end

Bind(cfg.talk, {
  action = function()
    if pending then
      pending:Cancel()
      pending = nil
    end
    if not held then
      held = cfg.output
      HID.Down(held)
    end
  end,
  release = function()
    pending = After(cfg.tail, function()
      pending = nil
      release()
    end)
  end,
})

function OnStop()
  if pending then
    pending:Cancel()
  end
  release()
end

3 files, 2.6 KB.